-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
executable file
·116 lines (89 loc) · 2.1 KB
/
Copy pathclient.py
File metadata and controls
executable file
·116 lines (89 loc) · 2.1 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from __future__ import print_function
from Adafruit_Thermal import *
import HTMLParser
import json
import os
import requests
import RPi.GPIO as IO
import time
from unidecode import unidecode
consumer_key = os.environ['CONSUMER_KEY']
consumer_secret = os.environ['CONSUMER_SECRET']
url = os.environ['URL']
title = os.environ['TITLE']
subtitle = os.environ['SUBTITLE']
author = os.environ['AUTHOR']
# Initialize printer
printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5)
# Print welcome message
printer.print(unidecode(
HTMLParser.HTMLParser().unescape(title)
)
)
printer.feed(1)
printer.print(unidecode(
HTMLParser.HTMLParser().unescape(subtitle)
)
)
printer.feed(1)
printer.print(unidecode(
HTMLParser.HTMLParser().unescape(author)
)
)
printer.feed(1)
printer.print(unidecode(
HTMLParser.HTMLParser().unescape('2018')
)
)
printer.feed(4)
IO.setmode(IO.BOARD)
IO.setup(29, IO.OUT)
IO.output(29, True)
time.sleep(2)
IO.output(29, False)
IO.cleanup()
def setup():
# LED configuration
IO.setmode(IO.BOARD)
IO.setup(33, IO.OUT)
IO.setup(31, IO.OUT)
IO.setup(29, IO.OUT)
def get_tweet():
IO.output(33, True)
time.sleep(1)
tweet = json.loads(requests.get(url).text)
IO.output(33, False)
return tweet
def start_printing(tweet):
'''
TODO: Implement JSON parse
'''
# Printer LED on
IO.output(31, True)
time.sleep(1)
# Start printing
printer.inverseOn()
printer.print(' ' + '{:<31}'.format(tweet['user']))
printer.inverseOff()
printer.underlineOn()
printer.print('{:<32}'.format(tweet['date']))
printer.underlineOff()
# Remove HTML escape sequences
# and remap Unicode values to nearest ASCII equivalents
printer.print(unidecode(
HTMLParser.HTMLParser().unescape(tweet['text'])
)
)
printer.feed(6)
# Printer LED off
IO.output(31, False)
time.sleep(5)
IO.output(29, True)
time.sleep(1.5)
IO.output(29, False)
IO.cleanup()
time.sleep(40)
while True:
setup()
tweet = get_tweet()
start_printing(tweet)