adding fitbit shecdule + fixing macro balance chart

This commit is contained in:
2026-01-15 13:05:46 -08:00
parent 6972c9b8f9
commit ce6b107560
6 changed files with 177 additions and 145 deletions

14
main.py
View File

@@ -46,6 +46,7 @@ async def lifespan(app: FastAPI):
# Schedule the backup job - temporarily disabled for debugging
scheduler = BackgroundScheduler()
scheduler.add_job(scheduled_backup, 'cron', hour=0)
scheduler.add_job(scheduled_fitbit_sync, 'interval', hours=1)
scheduler.start()
logging.info("Scheduled backup job started.")
yield
@@ -152,6 +153,19 @@ def scheduled_backup():
backup_path = os.path.join(backup_dir, f"meal_planner_{timestamp}.db")
backup_database(db_path, backup_path)
def scheduled_fitbit_sync():
"""Sync Fitbit weight data."""
logging.info("DEBUG: Starting scheduled Fitbit sync...")
db = SessionLocal()
from app.services.fitbit_service import sync_fitbit_weight
try:
result = sync_fitbit_weight(db, scope="30d")
logging.info(f"Scheduled Fitbit result: {result}")
except Exception as e:
logging.error(f"Scheduled Fitbit sync failed: {e}")
finally:
db.close()
def test_sqlite_connection(db_path):
"""Test if we can create and write to SQLite database file"""