tail-like option added

The option is continuously (every 60 seconds) fetching
the atom feed of RecentChanges and display the changes
like the tail-like without stopping. The option is
including by default the --state option as this inherent
to its use.
This commit is contained in:
Alexandre Dulaunoy 2011-01-10 06:41:41 +01:00
parent 2a5c92f330
commit e603b5e6ff

View file

@ -25,15 +25,18 @@ from optparse import OptionParser
import time import time
import datetime import datetime
feedparser.USER_AGENT = "wikirc2text.py" feedparser.USER_AGENT = "wikirc2text - https://github.com/adulau/wikirc2text"
usage = "usage: %s url(s)" % sys.argv[0] usage = "usage: %s url(s)" % sys.argv[0]
parser = OptionParser(usage) 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("-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("-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() (options, args) = parser.parse_args()
if (options.tail):
options.state = True
if (options.state): if (options.state):
import shelve import shelve
import hashlib import hashlib
@ -44,23 +47,33 @@ if len(args) < 1 and not options.statesec:
exit() exit()
def core (): 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): if (options.state):
s.close() s.close()