Guest User

Untitled

a guest
Dec 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import tweepy
  2. from tweepy import OAuthHandler
  3. import json
  4. import time
  5.  
  6. consumer_key = ''
  7. consumer_secret = ''
  8. access_token = ''
  9. access_secret = ''
  10.  
  11. auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  12. auth.set_access_token(access_token, access_secret)
  13. api = tweepy.API(auth)
  14.  
  15. with open('tweet_json.txt', 'w') as file:
  16. for tweet in tweet_ids:
  17. try:
  18. tweet_data = api.get_status(tweet, tweet_mode='extended',
  19. wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
  20. json.dump(tweet_data._json, file, sort_keys = True, indent=4, ensure_ascii = False) # Add data to the file
  21. file.write('n') # Add new line after every tweet
  22. except:
  23. print("Error: " + str(tweet))
Add Comment
Please, Sign In to add comment