Spaces:
Sleeping
Sleeping
Download backend/calendar_generator.py from Presight-AI/app: direct link, hf CLI and curl.
- Browser
- Download file 2.32 kB
-
https://huggingface.co/spaces/Presight-AI/app/resolve/main/backend/calendar_generator.py
- Command line
-
hf download hf://spaces/Presight-AI/app/backend/calendar_generator.py
-
curl -L -o calendar_generator.py https://huggingface.co/spaces/Presight-AI/app/resolve/main/backend/calendar_generator.py
2.32 kB
| from datetime import datetime, timedelta | |
| from typing import List, Dict | |
| import uuid | |
| class CalendarGenerator: | |
| """ | |
| Generates .ics calendar files for prescription reminders | |
| """ | |
| def generate_ics(self, medicine_name: str, frequency: str, duration: str, start_date: datetime = None) -> str: | |
| """ | |
| Generate ICS content for a single medicine reminder | |
| """ | |
| if not start_date: | |
| start_date = datetime.now() | |
| # Parse frequency to determine interval (simplified) | |
| interval_hours = 24 | |
| count = 7 # Default 7 days | |
| freq_lower = frequency.lower() | |
| if "twice" in freq_lower or "bid" in freq_lower or "1-0-1" in freq_lower: | |
| interval_hours = 12 | |
| elif "thrice" in freq_lower or "tid" in freq_lower or "1-1-1" in freq_lower: | |
| interval_hours = 8 | |
| elif "four" in freq_lower or "qid" in freq_lower: | |
| interval_hours = 6 | |
| # Parse duration (simplified) | |
| if "day" in duration.lower(): | |
| try: | |
| import re | |
| days = int(re.search(r'\d+', duration).group()) | |
| count = days * (24 // interval_hours) | |
| except: | |
| pass | |
| # Create ICS content | |
| ics_lines = [ | |
| "BEGIN:VCALENDAR", | |
| "VERSION:2.0", | |
| "PRODID:-//AI Prescription App//EN", | |
| "CALSCALE:GREGORIAN", | |
| "METHOD:PUBLISH" | |
| ] | |
| current_time = start_date | |
| for i in range(count): | |
| uid = str(uuid.uuid4()) | |
| dt_start = current_time.strftime("%Y%m%dT%H%M00") | |
| dt_end = (current_time + timedelta(minutes=15)).strftime("%Y%m%dT%H%M00") | |
| ics_lines.extend([ | |
| "BEGIN:VEVENT", | |
| f"UID:{uid}", | |
| f"DTSTART:{dt_start}", | |
| f"DTEND:{dt_end}", | |
| f"SUMMARY:Take {medicine_name}", | |
| f"DESCRIPTION:Reminder to take {medicine_name}. Frequency: {frequency}", | |
| "STATUS:CONFIRMED", | |
| "END:VEVENT" | |
| ]) | |
| current_time += timedelta(hours=interval_hours) | |
| ics_lines.append("END:VCALENDAR") | |
| return "\n".join(ics_lines) | |