-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter_rest.py
42 lines (26 loc) · 1014 Bytes
/
twitter_rest.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
38
39
40
41
42
# Credit http://socialmedia-class.org/twittertutorial.html
import io
# Get JSON modules
import csv
try:
import json
except ImportError:
import simplejson as json
# import methods from the python "twitter" library
from twitter import Twitter, OAuth, TwitterHTTPError, TwitterStream
# import creds variables with my twitter creds in separate settings file
import twittercreds
ACCESS_TOKEN = twittercreds.ACCESS_TOKEN
ACCESS_SECRET = twittercreds.ACCESS_SECRET
CONSUMER_KEY = twittercreds.CONSUMER_KEY
CONSUMER_SECRET = twittercreds.CONSUMER_SECRET
oauth = OAuth(ACCESS_TOKEN, ACCESS_SECRET, CONSUMER_KEY, CONSUMER_SECRET)
# Initiate the connection to Twitter REST API
twitter = Twitter(auth=oauth)
# Search for latest tweets about "#braintumorthursday"
braintumorthursday = twitter.search.tweets(q='#BrainTumorThursday', result_type='recent', lang='en', count=10)
f = json.dumps(braintumorthursday, sort_keys=True, indent=2)
print f
file = open("tweets.json", "w")
file.write(f)
file.close()