prix-carburant / scheduler.py
SamDNX's picture
Deploy petrol map: interactive fuel-price PWA + Docker for HF Spaces
284e818
Raw
History Blame Contribute Delete
1.34 kB
"""Rebuild the static map twice a day, without serving it.
Use this when you host the generated output/ directory elsewhere (static hosting,
a CDN, GitHub Pages, etc.). To build *and* serve from one process — e.g. for a
container or local preview — run `python app.py` instead.
Usage:
python scheduler.py # build now, then rebuild at 07:00 and 19:00
python scheduler.py --once # build a single time and exit
"""
from __future__ import annotations
import argparse
import time
import traceback
import schedule
from build_map import generate
REFRESH_TIMES = ["07:00", "19:00"]
def safe_generate() -> None:
try:
generate()
except Exception:
print("Map generation failed:")
traceback.print_exc()
def main() -> None:
parser = argparse.ArgumentParser(description="Twice-daily fuel-price map rebuilder.")
parser.add_argument("--once", action="store_true", help="build once and exit")
args = parser.parse_args()
safe_generate() # always start with a fresh map
if args.once:
return
for when in REFRESH_TIMES:
schedule.every().day.at(when).do(safe_generate)
print(f"Scheduled rebuilds at {', '.join(REFRESH_TIMES)} (local time).")
while True:
schedule.run_pending()
time.sleep(30)
if __name__ == "__main__":
main()