Created
March 9, 2009 23:12
-
-
Save taboularasa/76548 to your computer and use it in GitHub Desktop.
Twitter Search with Python
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
http://search.twitter.com/search.json?q=%40human_bot | |
{ | |
"results": [{ | |
"text": "@human_bot Are you feeling okay? Sounds like you've been smoking some crack with the way you've been talking lately.", | |
"to_user_id": 5740619, | |
"to_user": "human_bot", | |
"from_user": "taboularasa", | |
"id": 1306533155, | |
"from_user_id": 6667424, | |
"iso_language_code": "en", | |
"source": "<a href="http:\/\/twitter.com\/">web<\/a>", | |
"profile_image_url": "http:\/\/static.twitter.com\/images\/default_profile_normal.png", | |
"created_at": "Tue, 10 Mar 2009 18:11:31 +0000" | |
}], | |
"since_id": 0, | |
"max_id": 1306533155, | |
"refresh_url": "?since_id=1306533155&q=%40human_bot", | |
"results_per_page": 15, | |
"completed_in": 0.030572, | |
"page": 1, | |
"query": "%40human_bot" | |
} |
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
from xml.dom import minidom | |
import sys, time, urllib | |
if len(sys.argv) != 2: | |
print "Please enter a search" | |
raise SystemExit | |
search = sys.argv[1] | |
id = 0 | |
while True: | |
url = "http://search.twitter.com/search.atom?rpp=20&q=%s&since_id=%s" % (search, id) | |
xml = urllib.urlopen(url) | |
doc = minidom.parse(xml) | |
entries = doc.getElementsByTagName("entry") | |
if len(entries) > 0: | |
entries.reverse() | |
for e in entries: | |
title = e.getElementsByTagName("title")[0].firstChild.data | |
pub = e.getElementsByTagName("published")[0].firstChild.data | |
id = e.getElementsByTagName("id")[0].firstChild.data.split(":")[2] | |
name = e.getElementsByTagName("name")[0].firstChild.data.split(" ")[0] | |
print "> " + name + ": " + title + " [" + pub + "]" | |
time.sleep(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment