-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet_access.py
37 lines (27 loc) · 1.02 KB
/
tweet_access.py
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
import json
import tweepy
from tweepy import OAuthHandler
import auth
CONSUMER_KEY = auth.CONSUMER_KEY
CONSUMER_SECRET = auth.CONSUMER_SECRET
OAUTH_TOKEN = auth.OAUTH_TOKEN
OAUTH_TOKEN_SECERT = auth.OAUTH_TOKEN_SECERT
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECERT)
api = tweepy.API(auth)
count = 50
query = 'Dublin'
# Get all status
results = [status for status in tweepy.Cursor(api.search, q=query).items(count)]
status_texts = [status._json['text'] for status in results]
screen_names = [status._json['user']['screen_name']
for status in results
for mention in status._json['entities']['user_mentions']]
hashtags = [ hashtag['text']
for status in results
for hashtag in status._json['entities']['hashtags'] ]
words = [word for text in status_texts for word in text.split() ]
print json.dumps(status_texts[0:5], indent=1)
print json.dumps(screen_names[0:5], indent=1)
print json.dumps(hashtags[0:5], indent=1)
print json.dumps(words[0:5], indent=1)