-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hex.py
111 lines (93 loc) · 2.92 KB
/
Hex.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
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
#!/usr/bin/env python
# Main control code for the HexLight
# 2013-04-23 Kevin Claytor
# Generic imports
from time import sleep
# Raw output method to the pins
#import out
# Import patters, letters, and the clock
#import patterns
#import letters
#import clock
# Import twitter methods
import twitterclock
import letters as ls
import patterns
import clock
import out
import re
from stoppable import stoppable
def parse_command(text):
try:
command = re.search('.*:',text).group().rstrip(':').replace('@tobleroneclock',
'').lstrip()
except:
command = ''
try:
options = re.search(':.*',text).group().lstrip(':').lstrip()
except:
options = ''
# in the case that the user didn't specify a command, assume the
# command was 'say'.
if command == '' and options == '':
command = 'say'
options = text.replace('@tobleroneclock', '').lstrip()
return command, options
# Tweet help statements back to the user
def tweethelp(thandle, command, options):
user = thandle.get_mentions_user()
if options == 'help':
text = "tweet 'help: subject' where subject = {say,clock,life}"
elif options == 'say':
text = "say: string || prints out 'string' to the display"
elif options == 'clock':
text = "clock: options || enables clock-mode where options = {analog,digital}"
elif options == 'life':
text = "life: selfstr goodstr negastr threshold numberon waittime || all optional"
else:
text = "I don't understand you. Tweet 'help: help' for a list of commands."
tweet = '@%s %s' % (user,text)
# Check that we didn't just post this message - we don't want to spam
lastpost = thandle.get_last_post()
if not tweet == lastpost:
thandle.post_text(tweet)
return
class clock_say:
def __init__(self, message):
self.message = message
def __call__(self):
print self.message
for char in self.message:
if char not in ls.letter_dict:
continue
out.set_states_all(ls.letter_dict[char])
sleep(1)
patterns.all_off().draw()
sleep(0.05)
sleep(5)
return
class tweet_monitor:
def __init__(self, thandle):
self.thandle = thandle
self.lasttweet = thandle.get_mentions_text()
def __call__(self):
changed = 0
if self.lasttweet != self.thandle.get_mentions_text():
changed = 1
self.lasttweet = self.thandle.get_mentions_text()
return changed
def main():
# Initalize Pi GPIO
out.initialize()
# Create a new twitter interface
thandler = twitterclock.tclock()
# Fake twitter for testing
#thandler = twitterclock.fakeclock()
while 1:
#if monitor.tweet_changed():
parse_command(thandler)
# Twitter api rate limit is 100 / hr
sleep(30)
return
if __name__=="__main__":
main()