/
main.py
161 lines (136 loc) · 4.56 KB
/
main.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from firebase import firebase
from firebase_token_generator import create_token
from pprint import pprint
import sys
import fontv
import ldp
"""
#Creates the Token necesarry for Authorization
# "private_key" in the credentials JSON
private_key = 'YOUR PRIVATE KEY HERE' # "client_email" in the credentials JSON
service_account_email = "YOUR EMAIL FROM SERVICE ACCOUNT"
auth_payload = {"auth_data": "foo", "other_auth_data": "bar"}
token = create_token(service_account_email, private_key, "user1", auth_payload)
#Access the firebase database
# FIREBASE -> PYTHON
fbs = firebase.FirebaseApplication('PROJECT URL', None)
authentication = firebase.FirebaseAuthentication('SECRET', 'EMAIL', extra={'id': 123})
fbs.authentication = authentication
print authentication.extra
#AUTHENTICATIONS
user = authentication.get_user()
user.firebase_auth_token = token
#print user.firebase_auth_token
"""
global cancel
global count
count = 0
cancel = False
#reg_users = fbs.get('/Users', None)
reg_users = [1,2,3,4,5]
pprint(reg_users)
for counter in reg_users:
global count
count += 1
def log_user(response):
global count
global cancel
if len(response) != count:
count = len(response)
cancel = True
print(count)
"""this is the tickers stuff"""
while True:
cancel = False
# the matrix is a representation of the led's that are lit on the 80x8 display
#
matrix = [[0 for i in xrange(80)] for i in xrange(8)]
#
# function to shift left all the vaules of the matrix array
# this allows us to put new data in the first column
#
def shiftmatrix():
for row in range(8):
for col in range(79, 0, -1):
matrix[row][col] = matrix[row][col - 1]
# end def
# function to read the matrix array and output the values to the display device
#
def showmatrix():
ldp.displayoff()
for row in reversed(range(8)):
for col in reversed(range(80)):
ldp.colourshift(matrix[row][col])
ldp.showrow(row)
# end def
#
# Main
#
# initialise the display
#
ldp.init()
#
# assign the command line args for the text and colour
#
textinput = str("{:,}".format(count*1000))
# textinput=str(sys.argv[1])
colour = 1
# append extra characters to text input to allow for wrap-around
textinput += ' :: '
# save the ascii values of the input characters into the inputarray
# the font module uses the ascii value to index the font array
inputarray = []
for char in textinput:
inputarray.append(ord(char))
# dotarray is 8 X n
# n is determined by the number of characters multiplyed by 8
# n will be len(dotarray[0]) after filling dotarray from characters
# in the inputarray
#
dotarray = [[] for i in xrange(8)]
#
# fill the dot array with the colour digits
# this is the dot pattern that we want to show
#
for row in range(8):
for ascii in inputarray:
# get the width of the character from the first element of the font variable
width = fontv.array[ascii][0]
binary = '{0:{fill}{align}{width}{base}}'.format(fontv.array[ascii][row + 1], base='b', fill='0', align='>',
width=width)
for digit in range(width):
if binary[digit] == '0':
dotarray[row].append(0)
else:
dotarray[row].append(colour)
#
# Continually output to the display until Ctrl-C
#
check = 0
while cancel == False:
try:
"""
response = fbs.get('/Users', None)
if len(response) != count:
count = len(response)
cancel = True
print(count)
"""
if check > 10:
#fbs.get_async('/Users', None, callback=log_user)
log_user([1,2,3,4,5])
check = 0
# loop around each column in the dotarray
for col in range(len(dotarray[0])):
for row in range(8):
# copy the current dotarray column values to the first column in the matrix
matrix[row][0] = (dotarray[row][col])
# now that we have updated the matrix lets show it
showmatrix()
# shift the matrix left ready for the next column
shiftmatrix()
check += 1
except KeyboardInterrupt:
ldp.clear()
print
print "Finished"