-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyAuditCompleter.py
188 lines (174 loc) · 6.61 KB
/
KeyAuditCompleter.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import openpyxl as xl
import datetime
# Return building letter and row index in Excel sheet for specified keycode.
def room_find(keycode, cChoice):
if cChoice == '1' or cChoice == '3':
if keycode in bCodes:
return 'B' + str(bCodes.index(keycode))
if keycode in cCodes:
return 'C' + str(cCodes.index(keycode))
if keycode in dCodes:
return 'D' + str(dCodes.index(keycode))
if keycode in eCodes:
return 'E' + str(eCodes.index(keycode))
if keycode in fCodes:
return 'F' + str(fCodes.index(keycode))
if keycode in gCodes:
return 'G' + str(gCodes.index(keycode))
if keycode in hCodes:
return 'H' + str(hCodes.index(keycode))
if keycode in iCodes:
return 'I' + str(iCodes.index(keycode))
if keycode in jCodes:
return 'J' + str(jCodes.index(keycode))
if keycode in kCodes:
return 'K' + str(kCodes.index(keycode))
else:
return 'L' + str(lCodes.index(keycode))
# Keycodes of each building.
bCodes = list(range(1549, 1708))
cCodes = list(range(1708, 1867))
dCodes = list(range(1158, 1390))
eCodes = list(range(804, 809)) + list(range(926, 1128)) + list(range(1133, 1158))
fCodes = list(range(834, 926))
gCodes = list(range(602, 804)) + list(range(809, 834)) + list(range(1128, 1133))
hCodes = list(range(1390, 1549))
iCodes = list(range(363, 602))
jCodes = list(range(1, 5)) + list(range(150, 174)) + list(range(176, 184)) + list(range(186, 363))
kCodes = list(range(5, 150)) + [174, 175, 184, 185]
lCodes = list(range(1, 401))
# Load audit book.
fillBook = xl.load_workbook(filename = '../Fill.xlsx')
# Setup for reading audit.
columns = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L']
# Determine what buildings to anticipate.
complexChoice = input('\nPlease choose a complex:\n1. Vista\n2. Villas\n3. Both\n\n')
while complexChoice != '1' and complexChoice != '2' and complexChoice != '3':
print('\nInvalid choice, please input 1, 2 or 3\n')
complexChoice = input('\n1. Vista\n2. Villas\n3. All?\n\n')
if (complexChoice == '1' or complexChoice == '3'):
print('\nUsing Vista keycodes.')
else:
print('\nUsing Villas Keycodes.')
inputKey = input(
'\nPlease begin entering keycodes.\n'
'Enter h for help. Enter x to exit.\n\n')
# Switch from Vista to Villas for doing all keys.
if complexChoice == '3' and inputKey == 'x':
complexChoice = '2'
print("\nSwitching to Villas keycodes.\n")
inputKey = input(
'\nPlease begin entering keycodes.\n'
'Enter h for help. Enter x to exit.\n\n')
# Continuously read for input.
while inputKey != 'x':
# Print help menu.
if inputKey == 'h':
print(
'\nFormat of keycodes:\n'
'INPUT = KEYCODE. .COMMENT\n'
'KEYCODE = NUM.NUM.NUM | NUM.NUM.NUM.NUM\n'
'COMMENT = r | m | f | u | o | c | n | COMMENT.COMMENT | EPSILON\n'
'\n'
'Comment definitions:\n'
'r = room\n'
'm = mail\n'
'f = fob\n'
'u = urgent\n'
'o = lock out\n'
'c = lock change\n'
'n = reset normal keys\n'
's = reset studio keys\n'
'none = full set\n')
# inputKey is only numbers, so a full set.
elif inputKey.isdigit():
# room contains:
# room[0] -> building letter.
# int(room[1:]) -> row number in fillSheet for room.
# Must add 2 to int(room[1:]) to compensate for 0-indexing and header in Excel.
try:
room = room_find(int(inputKey), complexChoice)
fillSheet = fillBook[room[0]]
# Determine if room is a studio.
if fillSheet['G' + str(int(room[1:]) + 2)].value == 'Studio':
# Fill in full set for studio.
fillSheet['E' + str(int(room[1:]) + 2)].value = 1
fillSheet['F' + str(int(room[1:]) + 2)].value = 1
else:
# Fill in full set for regular room.
fillSheet['D' + str(int(room[1:]) + 2)].value = 1
fillSheet['E' + str(int(room[1:]) + 2)].value = 1
fillSheet['F' + str(int(room[1:]) + 2)].value = 1
except TypeError:
print('Please enter a valid keycode/comment.\n')
# inputKey has comments attached.
elif inputKey != 'x':
try:
room = room_find(int(inputKey[0:inputKey.index(' ')]), complexChoice)
fillSheet = fillBook[str(room[0])]
comments = inputKey[inputKey.index(' ') + 1:]
# Iterate through comments.
for comment in comments:
# Set room key.
if comment == 'r':
fillSheet['D' + str(int(room[1:]) + 2)].value = 1
# Set mail key.
elif comment == 'm':
fillSheet['E' + str(int(room[1:]) + 2)].value = 1
# Set fob.
elif comment == 'f':
fillSheet['F' + str(int(room[1:]) + 2)].value = 1
# Set urgent.
elif comment == 'u':
fillSheet['C' + str(int(room[1:]) + 2)].value = 0
fillSheet['G' + str(int(room[1:]) + 2)].value = "Urgent"
# Set lock out.
elif comment == 'o':
fillSheet['C' + str(int(room[1:]) + 2)].value = 0
fillSheet['G' + str(int(room[1:]) + 2)].value = "Lock out"
# Set lock change.
elif comment == 'c':
fillSheet['C' + str(int(room[1:]) + 2)].value = 0
fillSheet['G' + str(int(room[1:]) + 2)].value = "Lock change"
# Set normal keys.
elif comment == 'n':
fillSheet['C' + str(int(room[1:]) + 2)].value = 1
fillSheet['D' + str(int(room[1:]) + 2)].value = 0
fillSheet['E' + str(int(room[1:]) + 2)].value = 0
fillSheet['F' + str(int(room[1:]) + 2)].value = 0
fillSheet['G' + str(int(room[1:]) + 2)].value = ""
# Set studio keys.
elif comment == 's':
fillSheet['C' + str(int(room[1:]) + 2)].value = 0
fillSheet['D' + str(int(room[1:]) + 2)].value = 0
fillSheet['E' + str(int(room[1:]) + 2)].value = 0
fillSheet['F' + str(int(room[1:]) + 2)].value = 0
fillSheet['G' + str(int(room[1:]) + 2)].value = "Studio"
# Set full set for accidental whitespace.
elif comment.isspace():
if fillSheet['G' + str(int(room[1:]) + 2)].value == 'Studio':
# Fill in full set for studio.
fillSheet['E' + str(int(room[1:]) + 2)].value = 1
fillSheet['F' + str(int(room[1:]) + 2)].value = 1
else:
# Fill in full set for regular room.
fillSheet['D' + str(int(room[1:]) + 2)].value = 1
fillSheet['E' + str(int(room[1:]) + 2)].value = 1
fillSheet['F' + str(int(room[1:]) + 2)].value = 1
else:
print(
'One or more of your comments was not recognized.\n'
'Please reset this room and re-enter your comments.\n')
except ValueError:
print('Please enter a valid keycode/comment.\n')
except TypeError:
print('Please enter a valid keycode/comment.\n')
inputKey = input()
# Switch from Vista to Villas for doing all keys.
if complexChoice == '3' and inputKey == 'x':
complexChoice = '2'
print("\nSwitching to Villas keycodes.\n")
inputKey = input(
'\nPlease begin entering keycodes.\n'
'Enter h for help. Enter x to exit.\n\n')
fillBook.save("../Completed/" + datetime.datetime.today().strftime('%y%m%d') + "KeyAudit.xlsx")