import feedparser import urllib import os import sys ## Old URL couldn't get the image URL's from this one. ##_URL = "http://api.flickr.com/services/feeds/groups_pool.gne?id=40961104@N00&format=rss_200" _URL = "http://api.flickr.com/services/feeds/groups_pool.gne?id=40961104@N00&format=rss_200_enc" ## Get the filename from the url. def getFileFromURL(url): directory=os.curdir name="%s%s%s" % (directory, os.sep, url.split("/")[-1]) return name ## Create a download to download the image. def createDownload(url): instream=urllib.urlopen(url) return (instream, instream.info().getheader("Content-Length")) ## Download the image. def download(url): try: if os.path.exists(getFileFromURL(url)): print " Not Downloading, File Exists." else: outfile=open(getFileFromURL(url), "wb") fileName=outfile.name.split(os.sep)[-1] url, length=createDownload(url) if not length: length="?" print " Downloading %s (%s bytes) ..." % (url.url, length) if length!="?": length=float(length) bytesRead=0.0 for line in url: bytesRead+=len(line) # if length!="?": # print "%s: %.02f/%.02f kb (%d%%)" % (fileName,bytesRead/1024.0,length/1024.0,100*bytesRead/length) outfile.write(line) url.close() outfile.close() print " Done" except Exception, e: print " Error Downloading %s: %s" % (url, e) ## Get the feed from flickr. def getfeed(feed): rss = feedparser.parse(feed) print "Title: %s" % rss.feed.title print "There are %s entries in this feed" % len(rss.entries) print "" #i = 0 for i in xrange(len(rss.entries)): print " %s by %s" % (rss.entries[i].title, rss.entries[i].author) download(rss.entries[i].enclosures[0].href) # for i in xrange(len(rss.entries)): # print i # print rss.entries[i].title # print rss.entries[i].author # print rss.entries[i].enclosures[0].href # # print getFileFromURL(rss.entries[i].enclosures[0].href) if __name__ == "__main__": print "Flickr Wallpaper Downloader" print " by Dale Nunns (dale@stuff.za.net)" print "" opener = urllib.FancyURLopener() f = opener.open(_URL) feed = f.read() getfeed(feed)