mirror of
https://github.com/adulau/wikirc2text.git
synced 2024-12-22 08:46:02 +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 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,8 +47,17 @@ if len(args) < 1 and not options.statesec:
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
def core ():
|
def core ():
|
||||||
|
|
||||||
|
if (options.tail):
|
||||||
|
r = sys.maxint
|
||||||
|
else:
|
||||||
|
r = 1
|
||||||
|
|
||||||
|
for x in xrange(r):
|
||||||
|
|
||||||
for url in args:
|
for url in args:
|
||||||
d = feedparser.parse(url)
|
d = feedparser.parse(url)
|
||||||
|
if x == 0:
|
||||||
print d.feed.title
|
print d.feed.title
|
||||||
for e in d['entries']:
|
for e in d['entries']:
|
||||||
nicedate = time.strftime("%a, %d %b %Y %H:%M:%S +0000", e.updated_parsed)
|
nicedate = time.strftime("%a, %d %b %Y %H:%M:%S +0000", e.updated_parsed)
|
||||||
|
@ -60,7 +72,8 @@ def core ():
|
||||||
print rcline
|
print rcline
|
||||||
else:
|
else:
|
||||||
print rcline
|
print rcline
|
||||||
|
if x > 1:
|
||||||
|
time.sleep(60)
|
||||||
|
|
||||||
if (options.state):
|
if (options.state):
|
||||||
s.close()
|
s.close()
|
||||||
|
|
Loading…
Reference in a new issue