From b4bede5b972f7d1cffc099cc65772ff5388b8953 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sat, 30 Apr 2022 10:01:24 -0700 Subject: [PATCH] add dryrun flag and adjust logging --- feedbot.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/feedbot.py b/feedbot.py index c01a907..8e8645b 100644 --- a/feedbot.py +++ b/feedbot.py @@ -11,17 +11,25 @@ import models as zdb from PIL import ImageFile SNAP_USER_DATA = os.environ.get('SNAP_USER_DATA') +dr = False @click.group(invoke_without_command=True) @click.pass_context @click.option('--db') @click.option('--prime', is_flag=True) @click.option('--debug', is_flag=True) +@click.option('--dryrun', is_flag=True) @click.version_option(version='0.1.0') -def main(ctx, db, prime, debug): +def main(ctx, db, prime, debug, dryrun): + global dr if debug: logging.basicConfig(level=logging.DEBUG) + else: + logging.basicConfig(level=logging.INFO) + + if dryrun: + dr = dryrun if SNAP_USER_DATA is None and db is not None: db_file = db @@ -78,8 +86,10 @@ def fetch(url, pnut_uid, fid, prime): logging.debug(f"skipping {link}...") except zdb.Entries.DoesNotExist: - entry = zdb.Entries(feedid=fid, link=link) - entry.save() + if not dr: + entry = zdb.Entries(feedid=fid, link=link) + entry.save() + if prime: logging.debug(f"saving {link}...") @@ -115,7 +125,11 @@ def pnutpost(entry, source, token): try: rx = re.compile('<.*?>') text = re.sub(rx, '', entry.summary) - p, meta = pnutpy.api.create_post(data={'text': text, 'raw': raw}) + + if dr: + logging.info({'text': text, 'raw': raw}) + else: + p, meta = pnutpy.api.create_post(data={'text': text, 'raw': raw}) except Exception: logging.exception("bad stuff")