/
simple.py
executable file
·61 lines (46 loc) · 1.54 KB
/
simple.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
#!/usr/bin/env python
import getpass
import bark_api as api
import sys
import datetime
from reader import USBSerialReader
from unsw_ldap import LdapLookup
def handle_swipe(reader, auth_token, device_id, event_id):
swipe = reader.read()
timestamp = datetime.datetime.now().isoformat()
print swipe
zid = raw_input("Cardholder Z-id:")
print "Looking up details of " + zid
user = ldap.get_user(zid)
print user['displayName']
print user['school']
print user['faculty']
enrol = raw_input("Add cardholder to society and upload swipe? [y/n]")
if enrol == 'y':
api.post_swipe(auth_token, device_id, event_id, timestamp, swipe)
api.create_identity(auth_token, swipe, zid)
print "Bark API Login"
username = raw_input("Username: ")
password = getpass.getpass()
print "UNSW LDAP Login (Zid + Zpass). Don't get this wrong..."
zid = raw_input("Zid: ")
zpass = getpass.getpass()
ldap = LdapLookup(zid, zpass)
print "Connecting to serial reader"
reader = USBSerialReader()
auth_token = api.get_auth_token(username, password)
events = api.get_events(auth_token)
print 'Select Event:'
for x in range(len(events)):
print str(x) + ': ' + events[x]['name']
event_number = int(raw_input())
event_id = events[event_number]['id']
print 'Event Id:', event_id
device_id = api.register_device(auth_token, event_id)
print 'Device Id:', device_id
while(True):
act = raw_input('(s)wipe, (q)uit?')
if act == 'q':
break;
elif act == 's':
handle_swipe(reader, auth_token, device_id, event_id)