forked from JackMcCrack/rss-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedreader.py
70 lines (58 loc) · 1.88 KB
/
feedreader.py
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
63
64
65
66
67
68
69
70
#!/usr/bin/env python2
import feedparser
import time
import threading
import html_output
from operator import itemgetter
class Feed(threading.Thread):
def __init__(self, url):
threading.Thread.__init__(self)
self.url = url
name = "undefined"
def setName(self, text):
self.name = text
def run(self):
self.start = time.time()
self.d = feedparser.parse(self.url)
self.end = time.time()
self.diff = self.end - self.start
if __debug__:
print("{:.3f}".format(self.diff) + " s\t" + self.url)
articles.append(self.d)
def iconbyurl(config, url=None):
if url:
get = (config for config in config if (config[2] == url))
for x in get:
return x[0]
feeds = [] #for each rss-feed one threade
config = [] #keeps config from input.txt
articles = [] #all articles from all feeds
output = [] #just pubished, title, link, feedurl
with open('/home/jack/RSS-Reader/input.txt', 'r') as f:
for line in f:
if not line.strip().startswith("#"):
(icon, name, url) = line.split(None, 2)
config.append((icon, name, url.strip()))
feed = Feed(url.strip())
feeds.append(feed)
if __debug__:
print(config)
for x in feeds:
x.start() #gather rss feed in a thread
for x in feeds:
x.join() #wait for of all threads to finish
for post in articles:
for x in post.entries:
if hasattr(x, 'published_parsed') and hasattr(x, 'title_detail'):
output.append((
x.published_parsed,
x.title,
x.link,
iconbyurl(config, x.title_detail.base),
x.title_detail.base
))
output = sorted(output, key=itemgetter(0), reverse=True)
html_output.header(config)
html_output.selectionbox(config)
html_output.unnumberedlist(output)
html_output.footer()