aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2020-12-05 15:44:33 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2020-12-05 15:44:33 +0100
commit2dcdaa9b8f5174fdde35174ae9fe611ae8d6a1c9 (patch)
tree2294b50d3775cfcd931258f2133a09df6175d019
parentfix variable name in user.py/_fields_base_read (diff)
downloadnewspipe-2dcdaa9b8f5174fdde35174ae9fe611ae8d6a1c9.tar.gz
newspipe-2dcdaa9b8f5174fdde35174ae9fe611ae8d6a1c9.tar.bz2
newspipe-2dcdaa9b8f5174fdde35174ae9fe611ae8d6a1c9.zip
new: [commands] Added a function which deletes read articles retrieved since more than 5 days ago.
-rwxr-xr-xnewspipe/commands.py19
1 files changed, 18 insertions, 1 deletions
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')
bgstack15