Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import tweepy
  2. import json
  3. import datetime
  4. import time
  5.  
  6. consumer_key = "jWMFlGVO7aGQUx9dYX2XMrb3A"
  7. consumer_secret = "DuHH2qZWcp9AAaadvzKWADP0URpn7XuITJ9ytDjEE92mrv8y4n"
  8. access_key = "1114448490300469249-qTxcuH05R38ZyxlHg7Moa0ke4i8DlU"
  9. access_secret = "XQU5GDwshkSeHvd5Lad8EauVYJ15Uv6T1oKhmnM1zrmic"
  10.  
  11. #● The text of the tweet.
  12. #● Date and time of the tweet.
  13. #● The number of favorites/likes.
  14. #● The number of retweets.
  15. #● Number of Images present in Tweet. If no image returns None."
  16.  
  17.  
  18. def get_tweets(username):
  19.  
  20. auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  21.  
  22. auth.set_access_token(access_key, access_secret)
  23.  
  24. api = tweepy.API(auth)
  25.  
  26. tweets = api.user_timeline(screen_name=username)
  27. data = {}
  28. data['iitd'] = []
  29.  
  30. tweets_for_csv1 = [tweet.text for tweet in tweets]
  31. tweets_for_csv2 = [tweet.created_at for tweet in tweets]
  32. tweets_for_csv3 = [tweet.favorite_count for tweet in tweets]
  33. tweets_for_csv4 = [tweet.retweet_count for tweet in tweets]
  34. tweets_for_csv5 = [tweet.retweet_count for tweet in tweets]
  35.  
  36. for i in range(len(tweets_for_csv1)):
  37. data['iitd'].append({'text': tweets_for_csv1[i], 'date-time': tweets_for_csv2[i],
  38. 'likes': tweets_for_csv3[i], 'retweets': tweets_for_csv4[i], 'media': tweets_for_csv5[i]})
  39. print (data)
  40.  
  41. if __name__ == '__main__':
  42.  
  43. get_tweets("twitter-handle")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement