#!/usr/bin/python # Prasenjeet Dutta, http://www.chaoszone.org/ # ************************************************************** # NOTE - this code no longer works, and is no longer necessary! # Day by Day now has an excellent feed at: # http://www.daybydaycartoon.com/atom.xml # ************************************************************** # This synthesizes an RSS feed for Day by Day because # Day by Day's main feed doesn't include the comics images. # # each permalink is like http://www.daybydaycartoon.com/?CartoonDate=7/25/2005 # each image url is like http://www.daybydaycartoon.com/Cartoons/07-24-2005.gif import urllib, re from xml.dom import minidom from time import time, gmtime, strftime def GetImageDatesFromFeed (): ctr = 0 datelist = [] linkPattern = re.compile(r'CartoonDate=(\d?\d)/(\d?\d)/(\d{4})') dbdRssUrl = urllib.urlopen('http://feeds.feedburner.com/dbdrepub') rss = minidom.parse(dbdRssUrl) permalinks = rss.getElementsByTagName('link') for permalink in permalinks: permalinkUrl = permalink.childNodes[0].toxml() if type(linkPattern.search(permalinkUrl)) == type(None): # if ctr != 0: # print 'Regex Error, permalinkUrl was: ' + permalinkUrl pass else: reMatches = linkPattern.search(permalinkUrl).groups() datelist.append((reMatches[0], reMatches[1], reMatches[2])) ctr += 1 return datelist def RssHeader (): print """ Day By Day by Chris Muir Follow Sam, Zed, Jan, and Damon as they take life 'day by day' http://www.daybydaycartoon.com """ def RssBody (datelist): for dateTuple in datelist: print """ %(day)s/%(month)s/%(year)s ]]> http://www.daybydaycartoon.com/?CartoonDate=%(day)s/%(month)s/%(year)s """ % { 'day':dateTuple[0], 'month':dateTuple[1], 'year':dateTuple[2], 'iday':int(dateTuple[0]), 'imonth':int(dateTuple[1]) } def RssFooter (): print "" def ExpiryTime (): # content expires 12 hours from now return strftime("%a, %d %b %Y %H:%M:%S UTC", gmtime(time() + 43200)) def Main (): print "Content-Type: application/rss+xml" print "Expires: " + ExpiryTime() + "\n" RssHeader() RssBody(GetImageDatesFromFeed()) RssFooter() if __name__ == '__main__': Main()