JSON parsing from an API and do something with it

From XPUB & Lens-Based wiki
Revision as of 14:33, 21 January 2011 by Aymeric Mansoux (talk | contribs) (Created page with "Using the Twitter API as an example. More particularly, we are fetching the most recent tweets containing the #cheese hashtag. See the Twitter API doc for more information. <so...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Using the Twitter API as an example. More particularly, we are fetching the most recent tweets containing the #cheese hashtag. See the Twitter API doc for more information.


import urllib2, json

url = 'http://search.twitter.com/search.json?q=%23cheese'
f = urllib2.urlopen(url)
data = json.load(f)

for r in data['results']:
    print r['from_user'] + ' says "' + r['text'] + '"'