From a4800d35a8d30e293bda6d5c667ddef5bb19de7c Mon Sep 17 00:00:00 2001 From: ash Date: Fri, 3 Apr 2026 18:26:52 +0100 Subject: [PATCH] added garth and updated get client --- app.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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()