-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathauto_exit.py
48 lines (36 loc) · 1.36 KB
/
auto_exit.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
import os
import django
from datetime import datetime, timedelta, date
def mark_exit():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'entryexit.settings')
django.setup()
yesterday = date.today() - timedelta(days=1)
from enter.models import record
try:
#Collect all entries that are IN
entries_to_update = record.objects.filter(status='IN', date=yesterday)
#Store their roll numbers in a list
roll_numbers = []
for entry in entries_to_update:
roll_numbers.append(entry.rollno)
# Mark them as out at 23:59:59
for entry in entries_to_update:
entry.exittime = entry.exittime if entry.exittime else "23:59:59"
entry.status = 'OUT'
entry.save()
#Mark them as in at 00:00:00
for roll_number in roll_numbers:
entry = record.objects.create(rollno=roll_number, date=date.today(), entrytime="00:01:00", status='IN')
entry.save()
return True
except Exception as e:
# You may want to log the error for further investigation
# logger.error(f"Error occurred: {e}")
print(e)
return False
if __name__ == "__main__":
success = mark_exit()
if success:
print("Entries have been updated.")
else:
print("Error occurred while updating entries.")