Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from operator import itemgetter
- import tweepy
- import time
- APIKey=input("API Key, Please.\n")
- APIKeysecret=input("And To Confirm, Your Secret Api Key.\n")
- AccessToken=input("Your Access Token?\n")
- AccessTokenSecret=input("And The Secret Token.\n")
- auth = tweepy.OAuthHandler(APIKey, APIKeysecret)
- auth.set_access_token(AccessToken, AccessTokenSecret)
- api = tweepy.API(auth)
- requests = 0
- try:
- redirect_url = auth.get_authorization_url()
- except tweepy.TweepError:
- input('Error! Invalid Token, Or No Internet. Press Enter Key, To Kill Program.')
- exit()
- requests += 1
- print("Access Granted. Continuing Normal Procedures.")
- time.sleep(1.5)
- while requests < 180 :
- data = api.trends_place(1)
- requests += 1
- trends = data[0]["trends"]
- trends = filter(itemgetter("tweet_volume"), trends)
- sorted_trends = sorted(trends, key=itemgetter("tweet_volume"), reverse=True)
- top_10_trend_names = '\n'.join(trend['name'] for trend in sorted_trends[:10])
- print("Printing...")
- time.sleep(5)
- with open("trends.txt", 'w') as trends_file:
- print(top_10_trend_names, file=trends_file)
- print(top_10_trend_names)
- print("Printed Trends, Moving On.")
- file_variable = open('trends.txt')
- all_lines_variable = file_variable.readlines()
- with open("IndividualTrends/0.txt", 'w') as a:
- print(all_lines_variable[0], file=a)
- with open("IndividualTrends/1.txt", 'w') as b:
- print(all_lines_variable[1], file=b)
- with open("IndividualTrends/2.txt", 'w') as c:
- print(all_lines_variable[2], file=c)
- with open("IndividualTrends/3.txt", 'w') as d:
- print(all_lines_variable[3], file=d)
- with open("IndividualTrends/4.txt", 'w') as e:
- print(all_lines_variable[4], file=e)
- with open("IndividualTrends/5.txt", 'w') as f:
- print(all_lines_variable[5], file=f)
- with open("IndividualTrends/6.txt", 'w') as g:
- print(all_lines_variable[6], file=g)
- with open("IndividualTrends/7.txt", 'w') as h:
- print(all_lines_variable[7], file=h)
- with open("IndividualTrends/8.txt", 'w') as i:
- print(all_lines_variable[8], file=i)
- with open("IndividualTrends/9.txt", 'w') as j:
- print(all_lines_variable[9], file=j)
- print("Logged 10 Trends.")
- atrendsresults = api.search('IndividualTrends/0.txt')
- btrendsresults = api.search('IndividualTrends/1.txt')
- ctrendsresults = api.search('IndividualTrends/2.txt')
- dtrendsresults = api.search('IndividualTrends/3.txt')
- etrendsresults = api.search('IndividualTrends/4.txt')
- ftrendsresults = api.search('IndividualTrends/5.txt')
- gtrendsresults = api.search('IndividualTrends/6.txt')
- htrendsresults = api.search('IndividualTrends/7.txt')
- itrendsresults = api.search('IndividualTrends/8.txt')
- jtrendsresults = api.search('IndividualTrends/9.txt')
- requests = requests + 10
- with open("IndividualTrends/9.txt", 'w') as jtrendssearchresults :
- print(api.search('TrendsResult/jtrendsresults.json'), file=jtrendssearchresults)
- print("Done.")
- time.sleep(900)
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement