diff --git a/wikirc2text.py b/wikirc2text.py index 59cf643..5c21c0f 100644 --- a/wikirc2text.py +++ b/wikirc2text.py @@ -25,15 +25,18 @@ from optparse import OptionParser import time import datetime -feedparser.USER_AGENT = "wikirc2text.py" +feedparser.USER_AGENT = "wikirc2text - https://github.com/adulau/wikirc2text" usage = "usage: %s url(s)" % sys.argv[0] parser = OptionParser(usage) parser.add_option("-s", "--state", action="store_true" ,dest="state", help="keep state of existing rcline seen and don't output them", default=False) parser.add_option("-c", "--cleanstate", dest="statesec", help="expire states existing more than number of seconds specified") - +parser.add_option("-t", "--tail", action="store_true", dest="tail", help="tail-like operation by continuously appending new changes (--state option is enable)", default=False) (options, args) = parser.parse_args() +if (options.tail): + options.state = True + if (options.state): import shelve import hashlib @@ -44,23 +47,33 @@ if len(args) < 1 and not options.statesec: exit() def core (): - for url in args: - d = feedparser.parse(url) - print d.feed.title - for e in d['entries']: - nicedate = time.strftime("%a, %d %b %Y %H:%M:%S +0000", e.updated_parsed) - rcline = e.links[0]['href'] + " by " +e.author_detail['name'] +" @ "+ nicedate - if (options.state): - sh = hashlib.md5() - sh.update(rcline.encode('utf-8')) - sh.digest() - shkey = sh.hexdigest() - if not (s.has_key(shkey)): - s[shkey] = time.mktime(datetime.datetime.now().timetuple()) - print rcline - else: - print rcline + if (options.tail): + r = sys.maxint + else: + r = 1 + + for x in xrange(r): + + for url in args: + d = feedparser.parse(url) + if x == 0: + print d.feed.title + for e in d['entries']: + nicedate = time.strftime("%a, %d %b %Y %H:%M:%S +0000", e.updated_parsed) + rcline = e.links[0]['href'] + " by " +e.author_detail['name'] +" @ "+ nicedate + if (options.state): + sh = hashlib.md5() + sh.update(rcline.encode('utf-8')) + sh.digest() + shkey = sh.hexdigest() + if not (s.has_key(shkey)): + s[shkey] = time.mktime(datetime.datetime.now().timetuple()) + print rcline + else: + print rcline + if x > 1: + time.sleep(60) if (options.state): s.close()