[mod_python] looping in mod_python not giving right output

Leif Orion leiforion at yahoo.com
Wed Nov 24 20:56:37 EST 2010


So I think I know the problem with this code, but I cannot seem to wrap my head around solving it. I am pulling a list of images from the flickr api and trying to post that list to a page. However I am only getting one image to show, instead of all of them (as I was hoping the iterator would handle).
Any help with getting this to show would be much appreciated. Still getting used to Python so my apologies if my code comes across a little bit juvenile.

Thanks,
Leif

Code as follows:

import flickrapi
import urllib2

from elementtree.ElementTree import Element
from xml.etree import ElementTree

api_key = '639e38a13fd763a7cdfc5a37813fdf56'

flickr = flickrapi.FlickrAPI(api_key)
sets = flickr.photosets_getList(user_id='26761534 at N00', format='rest')

urls = urllib2.urlopen('http://www.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key=639e38a13fd763a7cdfc5a37813fdf56&user_id=26761534@N00')
tree = ElementTree.parse(urls)

def index():
  for node in tree.getiterator():
    photoid = node.attrib.get('id')
    secrets = node.attrib.get('secret')
    server = node.attrib.get('server')
    farm = node.attrib.get('farm')
#   linkurl = 'http://farm%s.static.flickr.com/%s/%s_%s_b.jpg' % (farm, server, photoid, secrets)
    imgurl = 'http://farm%s.static.flickr.com/%s/%s_%s_m.jpg' % (farm, server, photoid, secrets)

  s = """\
<html><body>
<p> thumbnails</p><br><br>
<img src="%s"> <br>
</body></html>
"""
  return s % imgurl


      


More information about the Mod_python mailing list