Valkertown Home

2008-12-02-setting my desktop backgrounds from flickr part 2

Well after a while of testing my previous script I found that the overall quality of the images I was getting was good but from time to time a really horrible image would popup, so I decided to try another approach.

I have heard about Flickr's interestingness, and decided to see if I could grab images from there, since the overall quality appeared to be really good. I hat to acquire an API key to do it.

But well here's what I got:

For this I dropped feedparser and had to use simplejson for python


import simplejson
import urllib
import random



def build_query(method,data=None):
    retval = FLICKR_REST + "?"
    base_params = urllib.urlencode({
    if data is not None:
        extra_params = urllib.urlencode(data)
        extra_params = ""
    retval += base_params + "&" + extra_params
    return retval

def do_query(method,data=None):
    conn = urllib.urlopen(build_query(method,data))
    data =
    data =data[:-1].replace("jsonFlickrApi(","")
        retval = simplejson.loads(data)
        print data
        retval = {}
    return retval
photofeed = do_query("getList")
photo = random.choice(photofeed['photos']['photo'])
photosizes = do_query("getSizes",(("photo_id",photo['id']),))

## photo['url'] =
print  photosizes['sizes']['size'][-1]['source']
## print "%(title)s %(url)s" % photo

It goes well with the previous shells script.


comments powered by Disqus

© 2008-2012 Carlos A. Perilla deepspawn at valkertown dot org | Based on original design by Andreas Viklund