Skip to content

Instantly share code, notes, and snippets.

@dbr
Created December 31, 2009 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbr/266583 to your computer and use it in GitHub Desktop.
Save dbr/266583 to your computer and use it in GitHub Desktop.
Twitter search history
#!/usr/bin/env python2.6
"""Twitter's "advanced" search can't seem to find a users tweet from more
than a few days ago, so I wrote this simple function to do so.
Not good code, not very efficient, only finds the most recent occurrence of
the word.. but it worked for what I needed
"""
import urllib
import simplejson as json
def searchTwitterUser(user, term):
u = "http://twitter.com/statuses/user_timeline.json?screen_name=%s&count=200&page=%%s" % user
for x in range(100):
print "Getting page %s" % x
src = urllib.urlopen(u % x).read()
print "done"
tweets = json.loads(src)
for t in tweets:
if term.lower() in t['text'].lower():
return t
print searchTwitterUser("_dbr", "someterm")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment