1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#!/usr/bin/env python3
from watchnews import data, web, fetch, rss
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")
parser.add_argument("--rss", action='store_true',
help="Dump a RSS feeds")
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()
if args.rss:
print(rss.rss())
|