Created
July 7, 2011 19:40
-
-
Save Gautier/1070356 to your computer and use it in GitHub Desktop.
Group1 code dojo secret sauce
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
import urllib2 | |
import json | |
import urllib | |
API_URL = "http://search.twitter.com/search.json" | |
def find_a_tweet_without_twitter_stuff(tweets): | |
for tweet in tweets: | |
if not ("#" in tweet or "@" in tweet or "http://" in tweet): | |
yield tweet | |
def find_an_answer(q): | |
req = urllib.urlencode([("q", q), ("result_type", "recent"), | |
('rpp', '100'), ('lang', 'en')]) | |
raw = urllib2.urlopen(API_URL, data=req).read() | |
results = json.loads(raw)['results'] | |
tweets = [r['text'] for r in results] | |
candidates = list(find_a_tweet_without_twitter_stuff(tweets)) | |
return candidates | |
def find_interesting_stuff(words): | |
for word in words + ['psychology']: | |
tweets = find_an_answer(word) | |
if tweets: | |
return tweets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment