added garth and updated get client
This commit is contained in:
@@ -3,6 +3,7 @@ import datetime
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from garminconnect import Garmin
|
from garminconnect import Garmin
|
||||||
|
import garth
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@@ -35,20 +36,21 @@ def get_client():
|
|||||||
os.makedirs(TOKEN_PATH, exist_ok=True)
|
os.makedirs(TOKEN_PATH, exist_ok=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 1. Attempt to login using the tokens folder
|
|
||||||
print("🔄 Attempting to log in using stored tokens...")
|
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 = Garmin()
|
||||||
garmin_client.login(TOKEN_PATH)
|
|
||||||
print("✅ Logged into Garmin using cached tokens")
|
print("✅ Logged into Garmin using cached tokens")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ Token login failed or missing ({e}). Falling back to credentials...")
|
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 = Garmin(EMAIL, PASSWORD)
|
||||||
garmin_client.login()
|
garmin_client.login()
|
||||||
|
|
||||||
# 3. Save the newly acquired tokens to your persistent folder!
|
# 4. Save the newly acquired tokens to your persistent folder!
|
||||||
garmin_client.garth.dump(TOKEN_PATH)
|
garth.dump(TOKEN_PATH)
|
||||||
print("✅ Fresh login successful, tokens saved.")
|
print("✅ Fresh login successful, tokens saved.")
|
||||||
|
|
||||||
last_login_time = time.time()
|
last_login_time = time.time()
|
||||||
|
|||||||
Reference in New Issue
Block a user