This repository was archived by the owner on Aug 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtweceipt.py
More file actions
173 lines (78 loc) · 2.53 KB
/
tweceipt.py
File metadata and controls
173 lines (78 loc) · 2.53 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
import serialEscPos,twitter,time
rp = serialEscPos.serialEscPos()
api = twitter.Api()
got = {}
latest=0
searchterm = ""
slipprint = False
starttime = time.time()
stopbeforeprint = True
def printstatus(status):
global got,rp
if status.id in got:
return
got[status.id] = status.id
if stopbeforeprint:
print "In stop before print mode. Won't actually print.\n"
return
rp.doubleStrike(1)
rp.underline(1)
rp.centre()
rp.println("@" + unicode(status.user.screen_name).encode('ascii', 'ignore'))
rp.left()
rp.doubleStrike(0)
rp.underline(0)
rp.println(unicode(status.text).encode('ascii', 'ignore'))
rp.println("")
def prime(term):
global api,latest,searchterm
searchterm = term
res = api.GetSearch(term=searchterm,per_page=1)
if(len(res) > 0):
latest=res[0].id
printstatus(res[0])
def checkfornew():
print "running...\n"
global api,latest,searchterm
res = api.GetSearch(term=searchterm,per_page=5,since_id=latest)
for status in res:
if status.id > latest:
latest = status.id
printstatus(status)
def endslip():
global rp
if not rp.usingSlip():
print "Asked to end slip. No slip in use."
return
rp.ff()
#first wait for the slip to need removing:
while not rp.slipWaiting():
time.sleep(0.5)
#now wait for the slip to be removed
print "Please remove slip.\n"
while rp.slipWaiting():
time.sleep(0.5)
print "Thankyou.\n"
if slipprint:
rp.useSlip()
prime("\"is down\"")
while 1:
checkfornew()
for n in range( 30):
time.sleep(1)
if rp.slipAvailable() and not slipprint:
rp.useSlip()
rp.centre()
rp.doubleStrike(1)
rp.underline(1)
rp.println("Tweceipt Printer Stats")
rp.doubleStrike(0)
rp.underline(0)
rp.left()
rp.println("Started at: " + time.asctime(time.localtime(starttime)))
rp.println("Tweets printed: " + str(len(got)))
rp.println("That's " + str(len(got)/((time.time()-starttime)/3600)) + " tweets/hour")
endslip()
print "Started at: " + time.asctime(time.localtime(starttime))
print "Tweets printed: " + str(len(got))
print "That's " + str(len(got)/((time.time()-starttime)/3600)) + " tweets/hour"