Source

PyCessing / pycessing / data / examples / flickr-search.cess

Full commit
#pull a random image from flickr based on a search term
#you will need to set your flickr api_key for this to work

import json
import urllib2
import random


photo = None
searchterm = "hats"
flickrapi = "http://api.flickr.com/services/rest/?\
method=flickr.photos.search&format=json&api_key=3fb5ac218cbb2fe3a029529338ecaef0&nojsoncallback=1&text="


def setup():
    global photo
    
    pycessing.size(600,800)
    pycessing.noLoop = True
    
    request = urllib2.urlopen(flickrapi + searchterm)
    results = json.load(request)

    photo_list = results["photos"]["photo"]
    selected = random.choice(photo_list)
    
    imgurl = "http://farm" + str(selected["farm"]) + ".staticflickr.com/"
    imgurl += selected["server"] + "/" + selected["id"] + "_"
    imgurl += selected["secret"] + "_c.jpg"
    print "got image: " + imgurl
    
    request = urllib2.urlopen(imgurl)
    
    photo = Image(request)
    


    
def draw():
    photo.draw(1,1)