diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2020-11-03 08:00:16 +0100 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2020-11-03 08:00:16 +0100 |
commit | bbe80f478132caa5bd1e9826b1834362dabbbf9e (patch) | |
tree | 30aa3e7f90ef5bd743b909f6357c654d0fbb0249 | |
parent | fixed deletion of inactive users. users are now deleted in a for loop on the ... (diff) | |
download | newspipe-bbe80f478132caa5bd1e9826b1834362dabbbf9e.tar.gz newspipe-bbe80f478132caa5bd1e9826b1834362dabbbf9e.tar.bz2 newspipe-bbe80f478132caa5bd1e9826b1834362dabbbf9e.zip |
added a command to disable inactive users (number of months given in parameter).
-rwxr-xr-x | newspipe/commands.py | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/newspipe/commands.py b/newspipe/commands.py index ca586039..26f4b7e2 100755 --- a/newspipe/commands.py +++ b/newspipe/commands.py @@ -69,18 +69,34 @@ def delete_inactive_users(last_seen): "Delete inactive users (inactivity is given in parameter and specified in number of months)." filter = {} filter["last_seen__lt"] = date.today() - relativedelta(months=last_seen) - try: - users = UserController().read(**filter) - for user in users: - db.session.delete(user) - try: - print("Deleting user {}...".format(user.nickname)) - db.session.commit() - except: - db.session.rollback() - print("Inactive users deleted.") - except Exception as e: - print(e) + users = UserController().read(**filter) + for user in users: + db.session.delete(user) + try: + print("Deleting user {}...".format(user.nickname)) + db.session.commit() + except: + db.session.rollback() + print("Inactive users deleted.") + + +@application.cli.command("disable_inactive_users") +@click.option('--last-seen', default=6, help='Number of months since last seen.') +def disable_inactive_users(last_seen): + "Disable inactive users (inactivity is given in parameter and specified in number of months)." + filter = {} + filter["last_seen__lt"] = date.today() - relativedelta(months=last_seen) + users = UserController().read(**filter) + for user in users: + user.is_active = False + user.is_public_profile = False + user.automatic_crawling = False + try: + print("Updating user {}...".format(user.nickname)) + db.session.commit() + except: + db.session.rollback() + print("Inactive users disabled.") @application.cli.command("fetch_asyncio") |