I am trying to download tweets from twitter.
I have used python and Tweepy for this. Though I am new to both Python and Twitter API.
My Python script is as f
Instead of using global variables, I would reorganize the code in a python class
:
import tweepy
class TweetPrinter():
"""
Simple class to print tweets
"""
def __init__(self, consumer_key, consumer_secret, access_token,
access_token_secret):
self.consumer_key = consumer_key
self.consumer_secret = consumer_secret
self.access_token = access_token
self.access_token_secret = access_token_secret
self.auth = tweepy.OAuthHandler(self.consumer_key,
self.consumer_secret)
self.auth.set_access_token(access_token, access_token_secret)
def tweet_print(self):
api = tweepy.API(self.auth)
football_tweets = api.search(q="football")
for tweet in football_tweets:
print(tweet.text)
def main():
tweet_printer = TweetPrinter(my_consumer_key, my_consumer_secret,
my_access_token, my_access_token_secret)
tweet_printer.tweet_print()
if __name__ == '__main__':
main()