From 6080b38fb2b6b3c1017bdd34bb7552bc7e26a4a0 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sun, 22 Nov 2015 00:25:56 +0100 Subject: project restructure make it a proper python package --- watchnews-cli | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 watchnews-cli (limited to 'watchnews-cli') 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() + -- cgit v1.2.1