Created
January 8, 2014 17:15
-
-
Save tpoisot/8320470 to your computer and use it in GitHub Desktop.
Read random tweets, and tweets mentioning words related to ecology
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
#! /usr/bin/python2 | |
import json | |
from TwitterAPI import TwitterAPI | |
c_key = '...' | |
c_sec = '...' | |
t_key = '...' | |
t_sec = '...' | |
api = TwitterAPI(c_key, c_sec, t_key, t_sec) | |
stream_session = open('ecology.lines', 'a') | |
r = api.request('statuses/filter',{'track':'biodiversity, biological diversity, ecology, species richness, ecosystem services, ecosystem functioning, ecological', 'language':'en'}) | |
for item in r.get_iterator(): | |
try : | |
print item['text'] | |
stream_session.write(json.dumps(item)) | |
stream_session.write('\n') | |
except : | |
print "Parsing failed" | |
stream_session.close() |
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
#! /usr/bin/python2 | |
import json | |
from TwitterAPI import TwitterAPI | |
c_key = '...' | |
c_sec = '...' | |
t_key = '...' | |
t_sec = '...' | |
api = TwitterAPI(c_key, c_sec, t_key, t_sec) | |
stream_session = open('random.lines', 'a') | |
r = api.request('statuses/sample',{'language':'en'}) | |
for item in r.get_iterator(): | |
try : | |
print item['text'] | |
stream_session.write(json.dumps(item)) | |
stream_session.write('\n') | |
except : | |
print "Parsing failed" | |
stream_session.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment