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("")
>>> print d['entries'][0]['media_thumbnail']


[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 *