Permalink
Cannot retrieve contributors at this time
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?
ChatBotGroup/trendingTopics.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
82 lines (61 sloc)
2.72 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tweepy | |
import json | |
import webbrowser | |
def search(): | |
topic = input("Looking at the trendingTopics, which one would you like to know more about:\n") | |
new = 2; | |
url = "http://www.google.co.uk/search?q=" + topic | |
webbrowser.open(url, new=new) | |
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)) | |
for trend in trends[0]["trends"]: | |
print((trend["name"]).strip("#")) | |
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)) | |
for trend in trends[0]["trends"]: | |
print((trend["name"]).strip("#")) | |
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)) | |
for trend in trends[0]["trends"]: | |
print((trend["name"]).strip("#")) | |
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)) | |
for trend in trends[0]["trends"]: | |
print((trend["name"]).strip("#")) | |
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)) | |
for trend in trends[0]["trends"]: | |
print((trend["name"]).strip("#")) | |
search() | |
countries = "London = 1\nNew York = 2\nTokyo = 3\nDubai = 4\nSydney = 5\n" | |
print(countries) | |
choice = int(input("To select a city to view its current trendingTopics, select its corresponding number. \n")) | |
trending_topics(choice) |