mirror of
https://github.com/adulau/wikirc2text.git
synced 2024-12-22 00:35:59 +00:00
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:
parent
2a5c92f330
commit
e603b5e6ff
1 changed files with 31 additions and 18 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue