-
Notifications
You must be signed in to change notification settings - Fork 4
/
checkin.py
54 lines (46 loc) · 1.71 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
52
53
54
#!/usr/bin/env python3
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()]
# 获取当前日期和前两天日期
# timezone UTC+8
beijing_timezone = datetime.timezone(datetime.timedelta(hours=8))
today = datetime.datetime.now(beijing_timezone).date()
yesterday = today - datetime.timedelta(days=1)
day_before_yesterday = today - datetime.timedelta(days=2)
print(
"今天是:{}, 检查过去两天打卡情况: {} {}".format(
today.isoformat(), yesterday.isoformat(), day_before_yesterday.isoformat()
)
)
missed = 0
# 检查每个人的打卡情况
for user in users:
# 检查最近两天的所有文件名
found = False
for folder in [yesterday, day_before_yesterday]:
folder_path = folder.strftime('notes/%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} 今天没有打卡!')
print(f'当前{len(users)}位同学参与打卡,{missed}位老板缺卡,缺卡率:{missed/len(users)*100:.2f}%。请发2元红包{len(users)}份。谢谢老板!')