-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtwitter_trends.py
More file actions
40 lines (28 loc) · 1.26 KB
/
twitter_trends.py
File metadata and controls
40 lines (28 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#Connects to twitter and finds latest trends or popular posts on twitter and then returns them in a readable format.
import twitter
import json
CONSUMER_KEY = ' '
CONSUMER_SECRET = ' '
OAUTH_TOKEN = ' '
OAUTH_TOKEN_SECRET = ' ' #Make an an app at https://apps.twitter.com/ and from the apps page you can request
#these values I left blank
auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,CONSUMER_KEY, CONSUMER_SECRET)
twitter_api = twitter.Twitter(auth=auth)
#Nothing to see by displaying twitter_api except that it's now a
#defined variable.
#print twitter_api
WORLD_WOE_ID = 1
US_WOE_ID = 23424977
world_trends = twitter_api.trends.place(_id = WORLD_WOE_ID)
us_trends = twitter_api.trends.place(_id=US_WOE_ID)
#print world_trends
#print
#print us_trends (This returns what we want but in very difficult to read format.
#print json.dumps(world_trends,indent=1)
#print
#print json.dumps(us_trends, indent=1) (Returns what we want but there are some duplicates)
world_trends_set = set([trend['name'] for trend in world_trends[0]['trends']])
us_trends_set = set([trend['name'] for trend in us_trends[0]['trends']])
common_trends = world_trends_set.intersection(us_trends_set)
print common_trends
#Returns best format I found so far.