-
Notifications
You must be signed in to change notification settings - Fork 30
/
update_exit.py
32 lines (25 loc) · 935 Bytes
/
update_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
import os
import django
from datetime import datetime, timedelta
def update_entries():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'entryexit.settings')
django.setup()
from enter.models import record
try:
yesterday = datetime.now().date() - timedelta(days=2)
entries_to_update = record.objects.filter(status='IN', date__lte=yesterday)
for entry in entries_to_update:
entry.exittime = entry.exittime if entry.exittime else "23:30:00"
entry.status = 'OUT'
entry.save()
return True
except Exception as e:
# You may want to log the error for further investigation
# logger.error(f"Error occurred: {e}")
return False
if __name__ == "__main__":
success = update_entries()
if success:
print("Entries have been updated.")
else:
print("Error occurred while updating entries.")