mirror of
https://github.com/adulau/rss-tools.git
synced 2024-11-07 12:06:25 +00:00
chg: [rsscount] make rsscount.py enter the modern world with Python 3
This commit is contained in:
parent
ae264dceac
commit
db022e4204
1 changed files with 21 additions and 27 deletions
|
@ -11,51 +11,45 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import feedparser
|
import feedparser
|
||||||
import sys,os
|
import sys, os
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
|
||||||
feedparser.USER_AGENT = "rsscount.py +http://www.foo.be/"
|
feedparser.USER_AGENT = "rsscount.py +http://www.foo.be/"
|
||||||
|
|
||||||
|
|
||||||
usage = "usage: %prog url(s)"
|
usage = "usage: %prog url(s)"
|
||||||
parser = OptionParser(usage)
|
parser = OptionParser(usage)
|
||||||
|
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
if args is None:
|
if args is None:
|
||||||
print usage
|
print(usage)
|
||||||
|
|
||||||
|
|
||||||
counteditem = {}
|
counteditem = {}
|
||||||
|
|
||||||
for url in args:
|
for url in args:
|
||||||
|
|
||||||
d = feedparser.parse(url)
|
d = feedparser.parse(url)
|
||||||
|
for el in d.entries:
|
||||||
|
|
||||||
for el in d.entries:
|
if "modified_parsed" in el:
|
||||||
|
eldatetime = datetime.datetime.fromtimestamp(
|
||||||
|
time.mktime(el.modified_parsed)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
eldatetime = datetime.datetime.fromtimestamp(
|
||||||
|
time.mktime(el.published_parsed)
|
||||||
|
)
|
||||||
|
eventdate = eldatetime.isoformat(" ").split(" ", 1)
|
||||||
|
edate = eventdate[0].replace("-", "")
|
||||||
|
|
||||||
try:
|
if edate in counteditem:
|
||||||
eldatetime = datetime.datetime.fromtimestamp(time.mktime(el.modified_parsed))
|
counteditem[edate] = counteditem[edate] + 1
|
||||||
except AttributeError:
|
else:
|
||||||
# discard RSS without pubDate grrr...
|
counteditem[edate] = 1
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
eventdate = eldatetime.isoformat(' ').split(' ',1)
|
for k in list(counteditem.keys()):
|
||||||
edate = eventdate[0].replace("-","")
|
|
||||||
|
|
||||||
if counteditem.has_key(edate):
|
|
||||||
counteditem[edate] = counteditem[edate] + 1
|
|
||||||
else:
|
|
||||||
counteditem[edate] = 1
|
|
||||||
|
|
||||||
|
|
||||||
for k in counteditem.keys():
|
|
||||||
|
|
||||||
print unicode(k).encode("utf-8")+"\t"+ unicode(counteditem[k]).encode("utf-8")
|
|
||||||
|
|
||||||
|
|
||||||
|
print(f"{k}\t{counteditem[k]}")
|
||||||
|
|
Loading…
Reference in a new issue