add dryrun flag and adjust logging

This commit is contained in:
Morgan McMillian 2022-04-30 10:01:24 -07:00
parent db7db690a3
commit b4bede5b97

View file

@ -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")