diff --git a/app.py b/app.py index 949536d..b63cffe 100644 --- a/app.py +++ b/app.py @@ -3,6 +3,7 @@ import datetime import os import time from garminconnect import Garmin +import garth app = Flask(__name__) @@ -35,20 +36,21 @@ def get_client(): os.makedirs(TOKEN_PATH, exist_ok=True) try: - # 1. Attempt to login using the tokens folder print("🔄 Attempting to log in using stored tokens...") + # 1. Ask garth to resume the session from the folder + garth.resume(TOKEN_PATH) + # 2. If it succeeds, initialize Garmin without credentials! garmin_client = Garmin() - garmin_client.login(TOKEN_PATH) print("✅ Logged into Garmin using cached tokens") except Exception as e: print(f"⚠️ Token login failed or missing ({e}). Falling back to credentials...") - # 2. If it fails, do a normal login with username and password + # 3. If it fails, do a normal login with username and password garmin_client = Garmin(EMAIL, PASSWORD) garmin_client.login() - # 3. Save the newly acquired tokens to your persistent folder! - garmin_client.garth.dump(TOKEN_PATH) + # 4. Save the newly acquired tokens to your persistent folder! + garth.dump(TOKEN_PATH) print("✅ Fresh login successful, tokens saved.") last_login_time = time.time()