ToCode
📌 שבתות וחגים - מה קורה כשהמודל מנסה יותר מדי
נתתי ל Sol את הפרומפט הבא כדי לבנות תוכנית פייתון שמדלגת על שבתות וחגים, למשל בשביל לא לשלוח מייל או לחייב לקוחות בשבת:
create a new python project with uv
the app is a cron scheduler we should start it via a CLI
cron.py cronfile
cronfile is in the same format as any regular crontab EXCEPT it has a twist
each line also has a boolean indicating if the request should execute in Jewish holidays and Saturdays
(called "skip_shabatot_vehagim")
If skip_shabatot_vehagim is set that line shouldn't execute on Jewish holidays and Saturdays with religious date
boundaries
התוצאה היתה מרשימה. זה קובץ ה calendar.py שהוא יצר:
"""Protected intervals, starting the evening before each sacred civil date."""
import math
from dataclasses import dataclass
from datetime import UTC, date, datetime, timedelta
from functools import lru_cache
from zoneinfo import ZoneInfo
from astral import Observer, SunDirection
from astral.sun import sunset, time_at_elevation
from pyluach.dates import HebrewDate
class BoundaryError(ValueError):
"""The location has no calculable sunset or nightfall for a required date."""
@dataclass(frozen=True)
class ReligiousCalendar:
timezone: ZoneInfo = ZoneInfo("Asia/Jerusalem")
latitude: float = 31.778
longitude: float = 35.235
israel: bool = True
start_offset_minutes: float = 0
nightfall_degrees: float = 8.5
nightfall_minutes: float | None = None
def __post_init__(self) -> None:
for name, value, lower, upper in (
("latitude", self.latitude, -90, 90),
("longitude", self.longitude, -180, 180),
("start offset", self.start_offset_minutes, 0, 180),
("nightfall degrees", self.nightfall_degrees, 1, 30),
):
if not math.isfinite(value) or not lower <= value <= upper:
raise ValueError(f"{name} must be between {lower} and {upper}")
if self.nightfall_minutes is not None and (
72 ·