summaryrefslogtreecommitdiff
path: root/watchnews-cli
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2015-11-22 00:25:56 +0100
committerYves Fischer <yvesf-git@xapek.org>2015-11-22 00:25:56 +0100
commit6080b38fb2b6b3c1017bdd34bb7552bc7e26a4a0 (patch)
tree07b69c3c6a665ef290591e184ca0d2ba3b73fe01 /watchnews-cli
parent49ac3c20cb77b90493ce79b4e31cf0f58cba0116 (diff)
downloadwatchnews-6080b38fb2b6b3c1017bdd34bb7552bc7e26a4a0.tar.gz
watchnews-6080b38fb2b6b3c1017bdd34bb7552bc7e26a4a0.zip
project restructure
make it a proper python package
Diffstat (limited to 'watchnews-cli')
-rwxr-xr-xwatchnews-cli57
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()
+