add toggle to enable/disable posting to pnut

This commit is contained in:
Morgan McMillian 2022-06-12 10:41:09 -07:00
parent f7e7cd60b8
commit c7deb310b5
2 changed files with 22 additions and 3 deletions

View file

@ -21,7 +21,7 @@ dr = False
@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.option('--dryrun', is_flag=True)
@click.version_option(version='0.1.1') @click.version_option(version='0.2.0')
def main(ctx, db, prime, debug, dryrun): def main(ctx, db, prime, debug, dryrun):
global dr global dr
@ -61,6 +61,22 @@ def adduser(username, token):
except pnutpy.errors.PnutAuthAPIException: except pnutpy.errors.PnutAuthAPIException:
logging.error(f"pnut user token not valid") logging.error(f"pnut user token not valid")
@main.command()
@click.argument('uid')
def enable(uid):
'''Enable posts to pnut'''
user = zdb.User.get(pnut_uid=uid)
user.pnut_enabled = 1
user.save()
@main.command()
@click.argument('uid')
def disable(uid):
'''Disable posts to pnut'''
user = zdb.User.get(pnut_uid=uid)
user.pnut_enabled = 0
user.save()
@main.command() @main.command()
@click.argument('uid') @click.argument('uid')
@click.argument('url') @click.argument('url')
@ -95,10 +111,13 @@ def fetch(url, pnut_uid, fid, prime):
if prime: if prime:
logging.debug(f"saving {link}...") logging.debug(f"saving {link}...")
else: elif user.pnut_enabled:
logging.debug(f"posting {link}...") logging.debug(f"posting {link}...")
pnutpost(post, source, user.pnut_token) pnutpost(post, source, user.pnut_token)
else:
logging.debug(f"pnut disabled, saving {link}...")
except zdb.User.DoesNotExist: except zdb.User.DoesNotExist:
logging.error(f"user {pnut_uid} not found") logging.error(f"user {pnut_uid} not found")

View file

@ -2,7 +2,7 @@ from setuptools import setup
setup( setup(
name='feedbot', name='feedbot',
version='0.1.1', version='0.2.0',
py_modules=[ py_modules=[
'models', 'models',
'feedbot', 'feedbot',