-
Notifications
You must be signed in to change notification settings - Fork 0
/
spreadsheet.py
56 lines (43 loc) · 1.75 KB
/
spreadsheet.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
import datetime,gspread,random
from oauth2client.service_account import ServiceAccountCredentials
import emailing as em
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("credentials.json", scope)
client = gspread.authorize(creds)
sheet = client.open("Face recognition").sheet1
max_intime='16:00:00'
def enroll_person_to_sheet(name,email):
nrows = len(sheet.col_values(1))
pin=random.randint(999,9999)
sheet.update_cell(nrows+1,1,name)
sheet.update_cell(nrows+1,2,email)
sheet.update_cell(nrows+1,3,pin)
em.email_pin(email,pin)
def mark_all_absent():
now=datetime.datetime.now()
date=now.strftime('%m/%d/%Y').replace('/0','/')
if(date[0]=='0'):
date=date[1:]
datecell=sheet.find(date)
nrows = len(sheet.col_values(1))
for row in range(2,nrows+1):
sheet.update_cell(row,datecell.col,'absent')
def write_to_sheet(name):
now=datetime.datetime.now()
date=now.strftime('%m/%d/%Y').replace('/0','/')
if(date[0]=='0'):
date=date[1:]
time=now.strftime('%H:%M:%S')
namecell=sheet.find(name)
datecell=sheet.find(date)
if(sheet.cell(namecell.row,datecell.col).value =='absent' ):
if(time<max_intime):
sheet.update_cell(namecell.row,datecell.col,'present')
print('recorded')
em.send_email(sheet.cell(namecell.row,2).value,"present")
else:
# sheet.update_cell(namecell.row,datecell.col,'late')
print('late')
em.send_email(sheet.cell(namecell.row,2).value,"absent")
# else:
# print('already recorded')