Advertisement
Guest User

Code

a guest
Nov 21st, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.90 KB | None | 0 0
  1. from operator import itemgetter
  2. import tweepy
  3. import time
  4. APIKey=input("API Key, Please.\n")
  5. APIKeysecret=input("And To Confirm, Your Secret Api Key.\n")
  6. AccessToken=input("Your Access Token?\n")
  7. AccessTokenSecret=input("And The Secret Token.\n")
  8. auth = tweepy.OAuthHandler(APIKey, APIKeysecret)
  9. auth.set_access_token(AccessToken, AccessTokenSecret)
  10. api = tweepy.API(auth)
  11. requests = 0
  12. try:
  13.   redirect_url = auth.get_authorization_url()
  14. except tweepy.TweepError:
  15.  input('Error! Invalid Token, Or No Internet. Press Enter Key, To Kill Program.')
  16.  exit()
  17. requests += 1
  18. print("Access Granted. Continuing Normal Procedures.")
  19. time.sleep(1.5)
  20. while requests < 180 :
  21.  data = api.trends_place(1)
  22.  requests += 1
  23.  trends = data[0]["trends"]
  24.  trends = filter(itemgetter("tweet_volume"), trends)
  25.  sorted_trends = sorted(trends, key=itemgetter("tweet_volume"), reverse=True)
  26.  top_10_trend_names = '\n'.join(trend['name'] for trend in sorted_trends[:10])
  27.  print("Printing...")
  28.  time.sleep(5)
  29.  with open("trends.txt", 'w') as trends_file:
  30.     print(top_10_trend_names, file=trends_file)
  31.  print(top_10_trend_names)
  32.  print("Printed Trends, Moving On.")
  33.  file_variable = open('trends.txt')
  34.  all_lines_variable = file_variable.readlines()
  35.  with open("IndividualTrends/0.txt", 'w') as a:
  36.    print(all_lines_variable[0], file=a)
  37.  with open("IndividualTrends/1.txt", 'w') as b:
  38.    print(all_lines_variable[1], file=b)
  39.  with open("IndividualTrends/2.txt", 'w') as c:
  40.    print(all_lines_variable[2], file=c)
  41.  with open("IndividualTrends/3.txt", 'w') as d:
  42.    print(all_lines_variable[3], file=d)
  43.  with open("IndividualTrends/4.txt", 'w') as e:
  44.    print(all_lines_variable[4], file=e)
  45.  with open("IndividualTrends/5.txt", 'w') as f:
  46.    print(all_lines_variable[5], file=f)
  47.  with open("IndividualTrends/6.txt", 'w') as g:
  48.    print(all_lines_variable[6], file=g)
  49.  with open("IndividualTrends/7.txt", 'w') as h:
  50.    print(all_lines_variable[7], file=h)
  51.  with open("IndividualTrends/8.txt", 'w') as i:
  52.    print(all_lines_variable[8], file=i)
  53.  with open("IndividualTrends/9.txt", 'w') as j:
  54.    print(all_lines_variable[9], file=j)
  55.  print("Logged 10 Trends.")
  56.  atrendsresults = api.search('IndividualTrends/0.txt')
  57.  btrendsresults = api.search('IndividualTrends/1.txt')
  58.  ctrendsresults = api.search('IndividualTrends/2.txt')
  59.  dtrendsresults = api.search('IndividualTrends/3.txt')
  60.  etrendsresults = api.search('IndividualTrends/4.txt')
  61.  ftrendsresults = api.search('IndividualTrends/5.txt')
  62.  gtrendsresults = api.search('IndividualTrends/6.txt')
  63.  htrendsresults = api.search('IndividualTrends/7.txt')
  64.  itrendsresults = api.search('IndividualTrends/8.txt')
  65.  jtrendsresults = api.search('IndividualTrends/9.txt')
  66.  requests = requests + 10
  67.  with open("IndividualTrends/9.txt", 'w') as jtrendssearchresults :
  68.    print(api.search('TrendsResult/jtrendsresults.json'), file=jtrendssearchresults)
  69.  print("Done.")  
  70.  time.sleep(900)
  71. exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement