-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
102 lines (82 loc) · 3 KB
/
functions.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
import cv2
import json
from datetime import datetime
import face_recognition
from pathlib import Path
import requests
def faceDetect(img):
imgV = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)
file_name = 'felon.jpg'
path_file = 'imgs/'+file_name
cv2.imwrite(path_file, imgV)
return json.dumps(path_file)
def findEncodings(images):
encodeList= []
for img in images:
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
encode = face_recognition.face_encodings(img)[0]
encodeList.append(encode)
return encodeList
def markAttendence(name):
with open('./attendence.csv','r+') as f:
myDataList = f.readlines()
nameList = []
# print("nameList", nameList)
lastentry=''
entry = lastentry.strip()
login = "http://64.227.130.2:5000/api/v1/userTimeEntry/logTime/"+name
result = requests.post(login)
d = result.json()
print ('d', d)
print ('result', result.json())
print('login', login)
r = requests.get("http://64.227.130.2:5000/api/v1/auth/login_with_id")
d = r.json()
for employee in d['data']:
# firstname = data['firstname']
id = employee['id']
firstname = employee['firstname']
# print(id)
# print(firstname)
if id == name.lower() :
name = firstname
# print('name...', name)
else :
None
for line in myDataList:
data = line.split(",")
x = data[0]
if x == name:
nameList.append(x)
entry=data[3]
if name not in nameList :
now = datetime.now()
dtstring = now.strftime('%b-%d-%Y, %H:%M:%S')
f.writelines(f'\n{name}, {dtstring}, {"in"}')
print('welcome', name)
elif name in nameList :
if entry==" out\n" or entry==" out" :
now = datetime.now()
dtstring = now.strftime('%b-%d-%Y, %H:%M:%S')
f.writelines(f'\n{name}, {dtstring}, {"in"}')
print(name,', lastentry =',entry)
elif entry==" in\n" or entry==" in":
now = datetime.now()
dtstring = now.strftime('%b-%d-%Y, %H:%M:%S')
f.writelines(f'\n{name}, {dtstring}, {"out"}')
print(name,', lastentry =',entry)
else :
print(4)
print('error',entry, name)
else :
print('ERORRRR.....!!!')
# def login(name):
# for id in name:
# # if id == name :
# login = "http://64.227.130.2:5000/api/v1/userTimeEntry/logTime/"+id
# result = requests.post(login)
# print ('result', result)
# def retrive(ids):
# for id in ids:
# # firstname = data['firstname']
# id = ids['id']