Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import tweepy
import json
import webbrowser
topics = ["Twitter", "topic"]
list1 = ["1"]
list2 = ["2"]
list3 = ["3"]
list4 = ["4"]
list5 = ["5"]
def search(y):
if y == 0:
return "Looking at the trendingTopics, which one would you like to know more about:\n"
else:
return "http://www.google.co.uk/search?q=" + y
def trending_topics(x):
# The following code section of code connects to Twitters API and authorises use of its operations
# It is based off the tutorial from Macro Bonzanini, who's tutorial can be found at the following link:
# https://marcobonzanini.com/2015/03/02/mining-twitter-data-with-python-part-1/
consumer_key = '8FAGQbWAHR3YvgB7qnDbiP6Gc'
consumer_secret = '7YdmCRuzWhIpdQBoIN8gfGSS5IHuKKCDivtHb6MSOf7xkFrnGs'
access_token = '1057021649701273602-ludjSICdEPAfhmeXBPTbVpBeJvFbJb'
access_token_secret = 'OZxlislafuep2hbDMnn7QjNPjeLEGR6m54BoUhcJ5PeAX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# This section performs the action of retrieving the trendingTopics from Twitter.
# It was based off the material from the following link:
# https://ronanlopes.me/tweepy-retrieving-trending-topics-twitter-specific-location/
if x == 1:
uk_woe_id = 23424975
uk_trends = api.trends_place(uk_woe_id)
trends = json.loads(json.dumps(uk_trends, indent=1))
result = ""
for trend in trends[0]["trends"]:
alltrends = (trend["name"]).strip("#")
result = alltrends + "\n" + result
return result
#search()
elif x == 2:
us_woe_id = 2459115
us_trends = api.trends_place(us_woe_id)
trends = json.loads(json.dumps(us_trends, indent=1))
result = ""
for trend in trends[0]["trends"]:
alltrends = (trend["name"]).strip("#")
result = alltrends + "\n" + result
return result
#search()
elif x == 3:
jp_woe_id = 1118108
japan_trends = api.trends_place(jp_woe_id)
trends = json.loads(json.dumps(japan_trends, indent=1))
result = ""
for trend in trends[0]["trends"]:
alltrends = (trend["name"]).strip("#")
result = alltrends + "\n" + result
return result
#search()
elif x == 4:
uae_woe_id = 1940345
uae_trends = api.trends_place(uae_woe_id)
trends = json.loads(json.dumps(uae_trends, indent=1))
result = ""
for trend in trends[0]["trends"]:
alltrends = (trend["name"]).strip("#")
result = alltrends + "\n" + result
return result
#search()
elif x == 5:
au_woe_id = 1105779
au_trends = api.trends_place(au_woe_id)
trends = json.loads(json.dumps(au_trends, indent=1))
result = ""
for trend in trends[0]["trends"]:
alltrends = (trend["name"]).strip("#")
result = alltrends + "\n" + result
return result
#search()
if x == 0:
countries = "London = 1\nNew York = 2\nTokyo = 3\nDubai = 4\nSydney = 5\n"
return "To select a city to view its current trending Topics, select its corresponding number. \n" + countries