Skip to content

Instantly share code, notes, and snippets.

@Gautier
Created July 7, 2011 19:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gautier/1070356 to your computer and use it in GitHub Desktop.
Save Gautier/1070356 to your computer and use it in GitHub Desktop.
Group1 code dojo secret sauce
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