-
Notifications
You must be signed in to change notification settings - Fork 39
/
checkin.py
51 lines (43 loc) · 1.53 KB
/
checkin.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
import os
import datetime
script_path = os.path.abspath(__file__)
script_dir = os.path.dirname(script_path)
reader_path = os.path.join(script_dir, 'readers.txt')
# 读取参与打卡的人员名单
with open(reader_path) as f:
users = [line.strip() for line in f.readlines()]
# 获取当前日期和前两天日期
today = datetime.date.today()
yesterday = today - datetime.timedelta(days=1)
day_before_yesterday = today - datetime.timedelta(days=2)
missed = 0
leave = 0
# 检查每个人的打卡情况
for user in users:
# 检查最近两天的所有文件名
found = False
if user[0] == '#' :
leave = leave + 1
continue
for folder in [yesterday, day_before_yesterday]:
folder_path = folder.strftime('homeworks/%Y/%-m/%-d')
folder_path = os.path.join(script_dir, folder_path)
for root, dirs, files in os.walk(folder_path):
for file in files:
if user.lower() in file.lower():
found = True
break
for dir in dirs:
if user.lower() in dir.lower():
found = True
break
if found:
break
if found:
break
# 检查打卡情况
if not found:
missed = missed + 1
print(f'{user} 今天没有打卡!')
attendees = len(users) - leave
print(f'当前{attendees}位同学参与打卡,{missed}位老板缺卡,缺卡率:{missed/attendees*100:.2f}%。请发2元红包{attendees}份。谢谢老板!')