change to github instead of pip
This commit is contained in:
@@ -2,8 +2,14 @@ FROM python:3.11-slim
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
|
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
RUN pip install --no-cache-dir git+https://github.com/cyberjunky/python-garminconnect.git@react
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ 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
|
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)
|
CACHE_TTL = int(os.getenv("CACHE_TTL", "300")) # seconds (default 5 mins)
|
||||||
|
TOKEN_PATH = "/app/data/garminconnect"
|
||||||
# --- GLOBAL CACHE ---
|
# --- GLOBAL CACHE ---
|
||||||
garmin_client = None
|
garmin_client = None
|
||||||
last_login_time = 0
|
last_login_time = 0
|
||||||
@@ -27,16 +27,31 @@ last_fetch_time = 0
|
|||||||
def get_client():
|
def get_client():
|
||||||
global garmin_client, last_login_time
|
global garmin_client, last_login_time
|
||||||
|
|
||||||
# Reuse client if already logged in
|
# Reuse client if already logged in and in memory
|
||||||
if garmin_client:
|
if garmin_client:
|
||||||
return garmin_client
|
return garmin_client
|
||||||
|
|
||||||
# Otherwise login once
|
# Ensure the directory in your volume exists
|
||||||
garmin_client = Garmin(EMAIL, PASSWORD)
|
os.makedirs(TOKEN_PATH, exist_ok=True)
|
||||||
garmin_client.login()
|
|
||||||
last_login_time = time.time()
|
|
||||||
|
|
||||||
print("✅ Logged into Garmin")
|
try:
|
||||||
|
# 1. Attempt to login using the tokens folder
|
||||||
|
print("🔄 Attempting to log in using stored tokens...")
|
||||||
|
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
|
||||||
|
garmin_client = Garmin(EMAIL, PASSWORD)
|
||||||
|
garmin_client.login()
|
||||||
|
|
||||||
|
# 3. Save the newly acquired tokens to your persistent folder!
|
||||||
|
garmin_client.garth.dump(TOKEN_PATH)
|
||||||
|
print("✅ Fresh login successful, tokens saved.")
|
||||||
|
|
||||||
|
last_login_time = time.time()
|
||||||
|
|
||||||
return garmin_client
|
return garmin_client
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
flask
|
flask
|
||||||
garminconnect
|
|
||||||
requests
|
requests
|
||||||
gunicorn
|
gunicorn
|
||||||
Reference in New Issue
Block a user