From d1c76d5979a1d580d8b1cae914d3a63f68091dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Sun, 14 Jun 2015 09:15:14 -0400 Subject: [PATCH] ENH: implement cleandb feature --- rss2email/command.py | 17 +++++++++++++++++ rss2email/main.py | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/rss2email/command.py b/rss2email/command.py index 529e6f2..ac8d493 100644 --- a/rss2email/command.py +++ b/rss2email/command.py @@ -65,6 +65,23 @@ def run(feeds, args): finally: feeds.save() +def cleandb(feeds, args): + "Keep only last seen entries in the database" + args.send = False + if not args.index: + args.index = range(len(feeds)) + try: + for index in args.index: + feed = feeds.index(index) + _LOG.info('resetting feed {}'.format(feed)) + feed.reset() + try: + feed.run(send=args.send) + except _error.RSS2EmailError as e: + e.log() + finally: + feeds.save() + def list(feeds, args): "List all the feeds in the database" for i,feed in enumerate(feeds): diff --git a/rss2email/main.py b/rss2email/main.py index 9e64848..ff40fc5 100644 --- a/rss2email/main.py +++ b/rss2email/main.py @@ -88,6 +88,13 @@ def run(*args, **kwargs): 'email', nargs='?', help='target email for the new feed') + cleandb_parser = subparsers.add_parser( + 'cleandb', help=_command.cleandb.__doc__.splitlines()[0]) + cleandb_parser.set_defaults(func=_command.cleandb) + cleandb_parser.add_argument( + 'index', nargs='*', + help='feeds to clean in the database (defaults to cleaning all feeds)') + run_parser = subparsers.add_parser( 'run', help=_command.run.__doc__.splitlines()[0]) run_parser.set_defaults(func=_command.run)