diff options
Diffstat (limited to 'watchnews-cli')
-rwxr-xr-x | watchnews-cli | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/watchnews-cli b/watchnews-cli new file mode 100755 index 0000000..53f5104 --- /dev/null +++ b/watchnews-cli @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +from watchnews import data, web, fetch + +import os +import argparse +import logging + + +logging.basicConfig(level=logging.INFO) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Process some integers.') + parser.add_argument('--add', metavar='URL', + help='add feed with URL') + parser.add_argument('--update', action='store_true', + help='Update all known feeds') + parser.add_argument('--update-feed', type=int, metavar='ID', + help='Update feed with ID') + parser.add_argument('--remove', type=int, metavar='ID', + help='Remove feed with ID') + parser.add_argument('--list', action='store_true', + help='List all registered feeds') + parser.add_argument('--web', action='store_true', + help='Run web interface') + parser.add_argument("--db", metavar="DBPATH", + default=os.path.join(os.path.dirname(__file__), "db.sqlite"), + help="Path to sqlite database file") + + args = parser.parse_args() + + data.init_sqlite(args.db) + + if args.update: + for feed in data.Feed.select(): + try: + fetch.update(feed) + except Exception as e: + logging.exception("Failed to update %s", feed.url) + if args.update_feed: + feed = data.Feed.get(data.Feed.id == args.update_feed) + if feed: + fetch.update(feed) + if args.add: + feed = data.Feed.create(url=args.add) + print("Added {}".format(feed)) + if args.remove: + feed = data.Feed.get(data.Feed.id == args.remove) + feed.delete_instance() + print("Removed {}".format(feed)) + if args.list: + for feed in data.Feed.select().order_by(data.Feed.created_date): + print("{0.id} - {1} - {0.title} - {0.url}".format( + feed, feed.created_date.strftime('%x %X'))) + if args.web: + web.get_app().run() + |