From 2dcdaa9b8f5174fdde35174ae9fe611ae8d6a1c9 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sat, 5 Dec 2020 15:44:33 +0100 Subject: new: [commands] Added a function which deletes read articles retrieved since more than 5 days ago. --- newspipe/commands.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/newspipe/commands.py b/newspipe/commands.py index 26f4b7e2..0faf18b8 100755 --- a/newspipe/commands.py +++ b/newspipe/commands.py @@ -11,7 +11,7 @@ from werkzeug.security import generate_password_hash import newspipe.models from newspipe.bootstrap import application, db -from newspipe.controllers import UserController +from newspipe.controllers import UserController, ArticleController logger = logging.getLogger("commands") @@ -99,6 +99,23 @@ def disable_inactive_users(last_seen): print("Inactive users disabled.") +@application.cli.command("delete_read_articles") +def delete_read_articles(): + "Delete read articles retrieved since more than 5 days ago." + filter = {} + filter["user_id__ne"] = 1 + filter["readed"] = True + filter["retrieved_date__lt"] = date.today() - relativedelta(days=5) + articles = ArticleController().read(**filter) + for article in articles: + try: + db.session.delete(article) + db.session.commit() + except: + db.session.rollback() + print("Read articles deleted.") + + @application.cli.command("fetch_asyncio") @click.option('--user-id', default=None, help='Id of the user') @click.option('--feed-id', default=None, help='If of the feed') -- cgit