zs

Zeitungsschau rss to email converter
git clone git://r-36.net/zs
Log | Files | Refs | LICENSE

commit 4367ca12c328ba46f3870016280e39c0ef252a0b
parent ca39520c711aabb6ec7e506847c0be557771eddc
Author: Christoph Lohmann <20h@r-36.net>
Date:   Fri,  2 Oct 2015 16:59:35 +0200

Add a silent option.

This option is useful for the cronjob output, where you only want to see if
something changed.

Diffstat:
zs | 22+++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/zs b/zs @@ -31,7 +31,7 @@ def sendfeed(db, ufeed): db.cfg["smtppassword"], db.cfg["smtpcmd"], \ db.cfg["smtpuselocal"]) -def run(db, selfeed=None, dryrun=False): +def run(db, selfeed=None, dryrun=False, onlychanges=False): feeduris = db.listfeeds() if feeduris != None and selfeed in feeduris: @@ -44,7 +44,8 @@ def run(db, selfeed=None, dryrun=False): retries = db.getretry(feeduri) estr = None - print("fetch %s" % (feeduri)) + if onlychanges != True: + print("fetch %s" % (feeduri)) curfeed = None try: curfeed = feed.fetch(feeduri) @@ -92,7 +93,7 @@ def run(db, selfeed=None, dryrun=False): db.mergefeed(feeduri, curfeed) ufeed = db.unreadarticles(feeduri) - if len(ufeed["articles"]) > 0: + if len(ufeed["articles"]) > 0 and onlychanges != True: print("cur %d unread %d" % (clen, \ len(ufeed["articles"]))) debug(ufeed) @@ -102,7 +103,7 @@ def run(db, selfeed=None, dryrun=False): def usage(app): app = os.path.basename(app) - sys.stderr.write("usage: %s [-dh] cmd\n" % (app)) + sys.stderr.write("usage: %s [-dhs] cmd\n" % (app)) sys.exit(1) def main(args): @@ -110,16 +111,19 @@ def main(args): retval = 0 try: - opts, largs = getopt.getopt(args[1:], "hd") + opts, largs = getopt.getopt(args[1:], "hds") except getopt.GetoptError as err: print(str(err)) usage(args[0]) + silent = False for o, a in opts: if o == "-h": usage(args[0]) elif o == "-d": dodebug = True + elif o == "-s": + silent = True else: usage(args[0]) @@ -130,15 +134,15 @@ def main(args): if largs[0] == "run": if len(largs) > 1: - run(db, largs[1]) + run(db, largs[1], onlychanges=silent) else: - run(db) + run(db, onlychanges=silent) elif largs[0] == "dryrun": if len(largs) > 1: - run(db, largs[1], dryrun=True) + run(db, largs[1], dryrun=True, onlychanges=silent) else: - run(db, dryrun=True) + run(db, dryrun=True, onlychanges=silent) elif largs[0] == "cfg": if len(largs) < 2: