-
Notifications
You must be signed in to change notification settings - Fork 0
/
reddit2lcd.py
executable file
·74 lines (45 loc) · 1.25 KB
/
reddit2lcd.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
71
72
73
74
#! /usr/bin/python
import serial
import time
import feedparser
# ---- RSS Feed Parser
d = feedparser.parse('http://www.reddit.com/r/vancouver/new/.rss')
latestpost = d['entries'][0]['title'].encode('utf-8')
chars_int = len(latestpost)
chars_str = str(chars_int)
# ---- Character counters
char_count1 = int("0")
char_count2 = int("16")
# ---- Set up the serial connection
s = serial.Serial(
port='/dev/ttyACM0',
baudrate=9600,
)
# ---- Wait for the Serial to initialize
time.sleep(2)
if chars_int > 16:
while char_count2 < chars_int+4:
s.write(latestpost[int(char_count1):int(char_count2)])
# print char_count1, char_count2
char_count1 = char_count1 + 2
char_count2 = char_count2 + 2
time.sleep(0.35)
print "----- Diagnostic Information -----"
print "Characters: " + chars_str
print "Serial Information: " + str(s)
print "Serial port open: " + str(s.is_open)
else:
s.write(latestpost[0:16])
print "----- Diagnostic Information -----"
print "Characters: " + chars_str
print "Serial Information: " + str(s)
print "Serial port open: " + str(s.is_open)
#s.write('latestpost')
'''
while True:
str = raw_input('Enter text: ')
str = str.strip()
if str == 'exit' :
break
s.write(str)
'''