2013-04-14 12:05:30 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# a at foo dot be - Alexandre Dulaunoy - http://www.foo.be/cgi-bin/wiki.pl/RssAny
|
|
|
|
#
|
|
|
|
# rsscount.py is a simple script to count how many items in a RSS feed per day
|
|
|
|
#
|
|
|
|
# The output is epoch + the number of changes separated with a tab.
|
|
|
|
#
|
2024-02-11 12:29:51 +00:00
|
|
|
# This is used to build statistic like the wiki creativity index.
|
2013-04-14 12:05:30 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
import feedparser
|
2024-02-11 12:29:51 +00:00
|
|
|
import sys, os
|
2013-04-14 12:05:30 +00:00
|
|
|
import time
|
|
|
|
import datetime
|
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
feedparser.USER_AGENT = "rsscount.py +http://www.foo.be/"
|
|
|
|
|
|
|
|
usage = "usage: %prog url(s)"
|
|
|
|
parser = OptionParser(usage)
|
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
if args is None:
|
2024-02-11 12:29:51 +00:00
|
|
|
print(usage)
|
2013-04-14 12:05:30 +00:00
|
|
|
|
|
|
|
counteditem = {}
|
|
|
|
|
|
|
|
for url in args:
|
|
|
|
|
2024-02-11 12:29:51 +00:00
|
|
|
d = feedparser.parse(url)
|
|
|
|
for el in d.entries:
|
2013-04-14 12:05:30 +00:00
|
|
|
|
2024-02-11 12:29:51 +00:00
|
|
|
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("-", "")
|
2013-04-14 12:05:30 +00:00
|
|
|
|
2024-02-11 12:29:51 +00:00
|
|
|
if edate in counteditem:
|
|
|
|
counteditem[edate] = counteditem[edate] + 1
|
|
|
|
else:
|
|
|
|
counteditem[edate] = 1
|
2013-04-14 12:05:30 +00:00
|
|
|
|
|
|
|
|
2024-02-11 12:29:51 +00:00
|
|
|
for k in list(counteditem.keys()):
|
2013-04-14 12:05:30 +00:00
|
|
|
|
2024-02-11 12:29:51 +00:00
|
|
|
print(f"{k}\t{counteditem[k]}")
|