forked from dalsmo/Loginbeta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blipper.py
executable file
·72 lines (66 loc) · 2.97 KB
/
blipper.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Simple script for registering members coming and going. """
import sqlite3 as lite
import time
import requests
import hasher
import getpass
while True:
while True:
try:
temp = getpass.getpass("Blip me! ")
rfId = hasher.encode(temp)
break
except ValueError:
print("Blip not recognised")
print("")
con = lite.connect('People.db')
with con:
cur = con.cursor()
cur.execute("SELECT * FROM People WHERE blipId = ?", (rfId,))
data = cur.fetchone()
if data is None: # there is no user with this ID tag
print("-----------------------------------------------")
print('There is no rfidtag named ', rfId, ' creating instance!')
nick_temp = input("input your nick: ")
temp = cur.lastrowid
if temp is None:
temp_id = 1
else:
temp_id = temp + 1
cur.execute("INSERT INTO People VALUES (?,?,?,?,?,?);",
(temp_id, rfId, nick_temp, 1, 0, time.time()))
requests.put('http://127.0.0.1:5001/', json = {'who': nick_temp, 'what': "login"})
try:
requests.get('http://192.168.42.12:5000/',timeout=0.001)
except:
print(" ")
print('you now exist and are logged in! dont forget to logout!')
print("-----------------------------------------------")
else: # there is user with this ID tag
if data[3] is 1: # is logged in => log hen out
time_spent = time.time() - data[5]
new_total_time = time_spent + data[4]
cur.execute("UPDATE People SET totalTime=?, isHere=? WHERE blipId=?",
(new_total_time, 0, rfId))
requests.put('http://127.0.0.1:5001/', json = {'who': str(data[2]), 'what': "logout"})
try:
requests.get('http://192.168.42.12:5000/',timeout=0.001)
except:
print(" ")
print("-----------------------------------------------")
print("Goodbye " + str(data[2]) + " your highscore is: " +
str(new_total_time))
print("-----------------------------------------------")
else: # is not logged in => log hen in
cur.execute("UPDATE People SET lastLogin=?, isHere=? WHERE blipId=?",
(time.time(), 1, rfId))
requests.put('http://127.0.0.1:5001/', json = {'who': str(data[2]), 'what': "login"})
try:
requests.get('http://192.168.42.12:5000/',timeout=0.001)
except:
print(" ")
print("-----------------------------------------------")
print("Welcome " + str(data[2]))
print("-----------------------------------------------")