add dryrun flag and adjust logging
This commit is contained in:
parent
db7db690a3
commit
b4bede5b97
1 changed files with 18 additions and 4 deletions
16
feedbot.py
16
feedbot.py
|
@ -11,17 +11,25 @@ import models as zdb
|
||||||
from PIL import ImageFile
|
from PIL import ImageFile
|
||||||
|
|
||||||
SNAP_USER_DATA = os.environ.get('SNAP_USER_DATA')
|
SNAP_USER_DATA = os.environ.get('SNAP_USER_DATA')
|
||||||
|
dr = False
|
||||||
|
|
||||||
@click.group(invoke_without_command=True)
|
@click.group(invoke_without_command=True)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
@click.option('--db')
|
@click.option('--db')
|
||||||
@click.option('--prime', is_flag=True)
|
@click.option('--prime', is_flag=True)
|
||||||
@click.option('--debug', is_flag=True)
|
@click.option('--debug', is_flag=True)
|
||||||
|
@click.option('--dryrun', is_flag=True)
|
||||||
@click.version_option(version='0.1.0')
|
@click.version_option(version='0.1.0')
|
||||||
def main(ctx, db, prime, debug):
|
def main(ctx, db, prime, debug, dryrun):
|
||||||
|
global dr
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
logging.basicConfig(level=logging.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:
|
if SNAP_USER_DATA is None and db is not None:
|
||||||
db_file = db
|
db_file = db
|
||||||
|
@ -78,8 +86,10 @@ def fetch(url, pnut_uid, fid, prime):
|
||||||
logging.debug(f"skipping {link}...")
|
logging.debug(f"skipping {link}...")
|
||||||
|
|
||||||
except zdb.Entries.DoesNotExist:
|
except zdb.Entries.DoesNotExist:
|
||||||
|
if not dr:
|
||||||
entry = zdb.Entries(feedid=fid, link=link)
|
entry = zdb.Entries(feedid=fid, link=link)
|
||||||
entry.save()
|
entry.save()
|
||||||
|
|
||||||
if prime:
|
if prime:
|
||||||
logging.debug(f"saving {link}...")
|
logging.debug(f"saving {link}...")
|
||||||
|
|
||||||
|
@ -115,6 +125,10 @@ def pnutpost(entry, source, token):
|
||||||
try:
|
try:
|
||||||
rx = re.compile('<.*?>')
|
rx = re.compile('<.*?>')
|
||||||
text = re.sub(rx, '', entry.summary)
|
text = re.sub(rx, '', entry.summary)
|
||||||
|
|
||||||
|
if dr:
|
||||||
|
logging.info({'text': text, 'raw': raw})
|
||||||
|
else:
|
||||||
p, meta = pnutpy.api.create_post(data={'text': text, 'raw': raw})
|
p, meta = pnutpy.api.create_post(data={'text': text, 'raw': raw})
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
Loading…
Reference in a new issue