#!/usr/bin/python2 # ripfeed.py # (C) Richard Whitty 2007 # Licence: as-is # Requires feedparser, from http://www.feedparser.org # This script hopes to take an RSS/Atom feed and dump it into a human readable format. # Either HTML or plain text. (only html atm) import feedparser import sys,getopt,codecs,locale from getopt import GetoptError # from: http://www.feedparser.org #from optparse import OptionParser # will replace this with optionparser after I'm done... #url = "http://lookingprettyill.blogspot.com/feeds/posts/default?max-results=5" url='' do_it_backwards=False def usage() : print "%s: rip an rss/atom feed and render to html." % sys.argv[0] print 'Usage: %s [-r|--reverse] [-u|--url=] /path/or/url/to/feed' print '-r/--reverse: prints the feed in reverse order, for example to do blogs in chronological order' print '-u/--url: the url of the feed to operate on. This qualifier can be ommitted.' return # oarse the arguments using gnu getopt def parse_args(argv) : global url global do_it_backwards if len(argv) == 0 : usage() sys.exit(1) else: try: opts,args = getopt.getopt(argv,"rhu:",["reverse","help","url="]) except getopt.GetoptError,ex: print "Error: %s" % ex.msg usage() sys.exit(1) for opt,arg in opts : if opt in ("-h","--help") : usage() sys.exit(1) elif opt in ("-r","--reverse") : do_it_backwards = True elif opt in ("-u","--url"): url=arg if url == '' : if len(args)>=1: url=args[0]; else: usage() sys.exit(1) return # Prints the html code associated with a single entry in the feed. def print_entry_html(entry): if(entry.has_key('link')) : print '