-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataController.py
More file actions
79 lines (67 loc) · 2.53 KB
/
DataController.py
File metadata and controls
79 lines (67 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
import requests
import json
import time
from multiprocessing import Value
class DataController():
def __init__(self, interrupt=None):
self.URL = 'https://ssu-corona.herokuapp.com'
# self.URL = 'http://localhost:3000'
if(interrupt != None):
self.interrupt = interrupt
def getUserDataByNFC(self, nfcid):
params = {'nfcid': nfcid}
response = requests.get(
self.URL + '/rest/user/identify', params=params)
state = response.status_code
result = response.json()
if(result['result'] == True):
return result['obj']
else:
return None
def addTempData(self, nfcid, temp):
params = {'nfcid': nfcid, 'temperature': temp}
response = requests.get(self.URL + '/rest/addTempData', params=params)
state = response.status_code
result = response.json()
print(result)
def addUser(self, nfcid, name, belong, id):
data = {'target': {'nfcid': nfcid,
'name': name, 'belong': belong, 'id': id}}
headers = {'Content-Type': 'application/json; charset=utf-8'}
response = requests.post(
self.URL + '/rest/user', headers=headers, data=json.dumps(data))
state = response.status_code
result = response.json()
return result['result']
def deleteUser(self, targets):
data = {'target': targets}
response = requests.delete(self.URL + '/rest/user', data=data)
result = response.json()
return result['result']
def getUserData(self):
time.sleep(1)
response = requests.get(self.URL + '/rest/user/withouttemp')
state = response.status_code
result = response.json()
if(result['result'] == True):
return result['content']
else:
return None
def login(self, id, password):
data = {'id': id, 'password': password}
# headers = {'Content-Type': 'application/json; charset=utf-8'}
response = requests.post(
self.URL + '/auth/signin', data=data)
state = response.status_code
result = response.json()
return result['flag']
def logout(self):
requests.get(self.URL + '/auth/signout')
if __name__ == '__main__':
dc = DataController()
# print(dc.addUser('12345678', '이름 테스트', '소속 테스트'))
# print(dc.getUserDataByNFC(1234))
# print(dc.login('admin', 'adminpassword'))
# dc.logout()
print(dc.getUserData())
# print(dc.deleteUser(659519540980))