Flickr feeds and feedparser

Gunnar asked this morning on #swig how to handle Flickr feeds, and especially images and thumbnails with feedparser. I remembered I hacked it once to make it work, but lost my changes with a server crash … hopefully I submitted a bug report about it.

Adding these 2 methods make it works as needed[1]:

def _start_media_content(self, attrsD):
  url = attrsD.get('url')
  if url:
    self._save('media_content', url)
def _start_media_thumbnail(self, attrsD):
  url = attrsD.get('url')
  if url:
    self._save('media_thumbnail', url)

Then, you can get thumbnails from Flickr feeds:

 
>>> import feedparser 
>>> d = feedparser.parse("http://api.flickr.com/services/feeds/photos_public.gne?id=33669349@N00&format=rss_200")
>>> print d['entries'][0]['media_thumbnail']
http://farm1.static.flickr.com/83/268382663_a5102bc6dd_s.jpg

Notes

[1] In case you don’t have any Python XML parser you will need to rename the second one _start_thumbnail, yet I didn’t check how to make the first one work in that case.

Leave a Reply

Your email address will not be published. Required fields are marked *