Download utils.py from AnimeKami/Cynthia: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/spaces/AnimeKami/Cynthia/resolve/main/utils.py
- Command line
-
hf download hf://spaces/AnimeKami/Cynthia/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/AnimeKami/Cynthia/resolve/main/utils.py
1.85 kB
| \ | |
| import datetime, pytz, os, pandas as pd | |
| ATTENDANCE_FOLDER = "attendance" | |
| os.makedirs(ATTENDANCE_FOLDER, exist_ok=True) | |
| IST = pytz.timezone("Asia/Kolkata") | |
| def get_today_files(): | |
| today = datetime.datetime.now(IST).strftime("%Y-%m-%d") | |
| csv_file = os.path.join(ATTENDANCE_FOLDER, f"attendance_{today}.csv") | |
| xlsx_file = os.path.join(ATTENDANCE_FOLDER, f"attendance_{today}.xlsx") | |
| return csv_file, xlsx_file | |
| def is_before_deadline(hour, minute): | |
| now = datetime.datetime.now(IST) | |
| deadline = now.replace(hour=hour, minute=minute, second=0, microsecond=0) | |
| return now <= deadline | |
| def mark_attendance(name, student_class): | |
| now = datetime.datetime.now(IST) | |
| date_str = now.strftime("%Y-%m-%d") | |
| time_str = now.strftime("%H:%M:%S") | |
| csv_file, xlsx_file = get_today_files() | |
| if os.path.exists(csv_file): | |
| df = pd.read_csv(csv_file) | |
| else: | |
| df = pd.DataFrame(columns=["Date","Name","Class","Time"]) | |
| # Prevent duplicates for same student on same date | |
| if not ((df["Name"]==name) & (df["Date"]==date_str)).any(): | |
| new_row = {"Date":date_str,"Name":name,"Class":student_class,"Time":time_str} | |
| df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True) | |
| df.to_csv(csv_file, index=False) | |
| df.to_excel(xlsx_file, index=False) | |
| print(f"🟢 Marked: {name} ({student_class}) at {time_str}") | |
| def reset_today_attendance(): | |
| csv_file, xlsx_file = get_today_files() | |
| # Overwrite with empty dataframe but keep headers | |
| df = pd.DataFrame(columns=["Date","Name","Class","Time"]) | |
| df.to_csv(csv_file, index=False) | |
| df.to_excel(xlsx_file, index=False) | |
| print("🔁 Today's attendance reset.")\ | |