forked from alexmburns/scroll-phat-hd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrss-feed.py
60 lines (48 loc) · 1.42 KB
/
rss-feed.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
#!/usr/bin/env python
#Thanks To campag for concept/code.
#Written by alexmburns.
from __future__ import print_function
import subprocess
import sys
import time
try:
import feedparser
except ImportError:
sys.exit("You need to install feedparser with: sudo pip install feedparser")
import scrollphathd
scrollphathd.set_brightness(0.5)
# Every refresh_interval seconds we'll refresh the news data, currently set to 30mins.
pause = 0.12
ticks_per_second = 1/pause
refresh_interval = 60*30
print("My RSS Feed") #Change Text as appropriate.
url = "http://feeds.feedburner.com/InterestingThingOfTheDay" #Insert your choice of RSS feed here.
def get_timeout():
return ticks_per_second * refresh_interval
def get_data():
# Get the data from rss feed
d = feedparser.parse(url)
entries = int(len(d['entries']))
val = " " + d['entries'][0]['title']
val +=" " + d['entries'][1]['title']
val +=" " + d['entries'][2]['title']
return val
timeout = get_timeout()
count = 0
msg = get_data()
scrollphathd.write_string(msg)
while True:
try:
scrollphathd.show()
scrollphathd.scroll()
time.sleep(0.05)
if(count > timeout):
msg = get_data()
scrollphathd.write_string(msg)
timeout = get_timeout()
count = 0
else:
count = count+ 1
except KeyboardInterrupt:
scrollphathd.clear()
sys.exit(-1)