Created
December 31, 2009 03:05
-
-
Save dbr/266583 to your computer and use it in GitHub Desktop.
Twitter search history
This file contains hidden or 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/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