Commit 726d066a authored by Alberto Cammozzo's avatar Alberto Cammozzo

improved diagnostics, feedback and dryrun mode

parent 299de68a
......@@ -36,22 +36,9 @@ from optparse import OptionParser
# populate feed sources db
def populateFeedSource(feedsourceDB,URL,homepage,site,active,protocol,name):
def populateFeedSource(feedsourceDB,feedSource):
from pymongo import MongoClient
ts= datetime.datetime.utcnow()
feedsourceDB.insert_one(
{
'dateAdded':ts,
'URL':URL,
'site':site,
'active':active,
'name':name,
'protocol':protocol,
'rating':'',
'oldRating':'',
'homepage': homepage,
}
)
feedsourceDB.insert_one(feedSource)
# log feed statistics and errors
def logEvent(verbose,logDB,prog,level,source,url,message):
......
......@@ -36,6 +36,7 @@ parser = ArgumentParser()
parser.add_argument("dbname", type=str,help='database name')
parser.add_argument("-s", "--server", dest="server", help="mongodb server address:port")
parser.add_argument("-v", "--verbose", action="store_true", help="be chatty")
parser.add_argument("-d", "--dryrun", action="store_true", help="dont write to db")
parser.add_argument("-i", "--interactive", action="store_true", dest="interactive", help="insert interactively")
(args) = parser.parse_args()
......@@ -54,10 +55,12 @@ now = datetime.datetime.now()
feedsource="feedsource"
feedsourceDB = db[feedsource]
homepage=False
if args.verbose:
print("TAB separated values in stdin: site name Homepage:True/False protocol:(rss|http) url")
if args.interactive:
# feedclass = input('feed class')
site = input('SITE (newspaper) ')
name = input('feed name ')
URL = input('feed URL ')
......@@ -65,12 +68,40 @@ if args.interactive:
protocol = input('protocol (rss|http)')
if hp.lower == "true":
homepage = True
if args.verbose: print(site, name, URL, protocol, str(homepage))
populateFeedSource(feedsourceDB,URL,homepage,site,True,protocol,name)
feedSource= {
'dateAdded':now,
'URL':URL,
'site':site,
'active':active,
'name':name,
'protocol':protocol,
# 'feedClass':feedclass,
'rating':'',
'oldRating':'',
'homepage': homepage,
}
if args.verbose: print(feedSource)
if (not args.dryrun):
populateFeedSource(feedsourceDB,feedSource)
else:
for line in sys.stdin:
#(feedclass,site,name,hp,protocol,URL)=line.strip().split("\t")
(site,name,hp,protocol,URL)=line.strip().split("\t")
print("protocol:"+protocol, "homepage:"+str(homepage), "site:"+site, "name:"+name, "URL:"+URL)
print(site,name,hp,protocol,URL)
if hp.lower == "true":
homepage= True
populateFeedSource(feedsourceDB,URL,homepage,site,True,protocol,name)
feedSource= {
'dateAdded':now,
'URL':URL,
'site':site,
'active':True,
'name':name,
'protocol':protocol,
# 'feedClass':feedclass,
'rating':'',
'oldRating':'',
'homepage': homepage,
}
if args.verbose: print(feedSource)
if (not args.dryrun):
populateFeedSource(feedsourceDB,feedSource)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment