Skip to content

Instantly share code, notes, and snippets.

@tieubao
Forked from tpoisot/ecology.py
Created January 9, 2014 04:26
Show Gist options
  • Save tieubao/8329396 to your computer and use it in GitHub Desktop.
Save tieubao/8329396 to your computer and use it in GitHub Desktop.
Read random tweets, and tweets mentioning words related to ecology
#! /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()
#! /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