remove garth

This commit is contained in:
ash
2026-04-03 18:36:52 +01:00
parent b0411ff807
commit da9f3cc781
2 changed files with 11 additions and 24 deletions
+10 -22
View File
@@ -3,7 +3,8 @@ import datetime
import os
import time
from garminconnect import Garmin
import garth
os.environ["GARMINTOKENS"] = "/app/data"
app = Flask(__name__)
@@ -15,12 +16,11 @@ GOAL_KM = float(os.getenv("GOAL_KM", "80"))
ALLOWED_TYPES = os.getenv("ALLOWED_TYPES", "running,treadmill_running").split(",")
TEST_MODE = os.getenv("TEST_MODE", "false").lower() == "true" # Check if TEST_MODE is enabled
CACHE_TTL = int(os.getenv("CACHE_TTL", "300")) # seconds (default 5 mins)
TOKEN_PATH = "/app/data/garminconnect"
CACHE_TTL = int(os.getenv("CACHE_TTL", "300"))
# --- GLOBAL CACHE ---
garmin_client = None
last_login_time = 0
cached_data = None
last_fetch_time = 0
@@ -28,33 +28,21 @@ last_fetch_time = 0
def get_client():
global garmin_client, last_login_time
# Reuse client if already logged in and in memory
if garmin_client:
return garmin_client
# Ensure the directory in your volume exists
os.makedirs(TOKEN_PATH, exist_ok=True)
print("🔄 Initializing Garmin client...")
try:
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()
print("✅ Logged into Garmin using cached tokens")
except Exception as e:
print(f"⚠️ Token login failed or missing ({e}). Falling back to credentials...")
# 3. If it fails, do a normal login with username and password
garmin_client = Garmin(EMAIL, PASSWORD)
garmin_client.login()
# 4. Save the newly acquired tokens to your persistent folder!
garth.dump(TOKEN_PATH)
print(" Fresh login successful, tokens saved.")
print("✅ Logged into Garmin (tokens loaded or newly saved)")
except Exception as e:
print(f" Failed to log into Garmin: {e}")
raise e
last_login_time = time.time()
return garmin_client
+1 -2
View File
@@ -1,4 +1,3 @@
flask
requests
gunicorn
garth
gunicorn