added test mode and adapted for docker

This commit is contained in:
ash
2026-03-31 08:29:24 +01:00
parent b87505250a
commit 5bf6e9083e
3 changed files with 16 additions and 11 deletions
+4 -7
View File
@@ -2,17 +2,14 @@ FROM python:3.11-slim
WORKDIR /app WORKDIR /app
# Install dependencies RUN apt-get update && apt-get install -y git
RUN git clone https://git.marlow.quest/ash/Garmin-API.git
COPY requirements.txt . COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
# Copy app
COPY app.py .
COPY logo.bin .
# Expose port
EXPOSE 5000 EXPOSE 5000
# Run app
RUN pip install gunicorn RUN pip install gunicorn
CMD ["gunicorn", "-b", "0.0.0.0:5000", "app:app"] CMD ["gunicorn", "-b", "0.0.0.0:5000", "app:app"]
+6
View File
@@ -12,6 +12,7 @@ PASSWORD = os.getenv("GARMIN_PASSWORD")
START_DATE = datetime.date.fromisoformat(os.getenv("START_DATE", "2026-01-01")) START_DATE = datetime.date.fromisoformat(os.getenv("START_DATE", "2026-01-01"))
GOAL_KM = float(os.getenv("GOAL_KM", "80")) GOAL_KM = float(os.getenv("GOAL_KM", "80"))
ALLOWED_TYPES = os.getenv("ALLOWED_TYPES", "running,treadmill_running").split(",") 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) CACHE_TTL = int(os.getenv("CACHE_TTL", "300")) # seconds (default 5 mins)
@@ -45,6 +46,11 @@ def get_garmin_data():
now = time.time() now = time.time()
# --- Return test data if in test mode ---
if TEST_MODE:
print("⚡ Test mode enabled, returning hardcoded data")
return {"total_km": 70, "goal_km": 100, "percent": 12.6, "status": "success"}
# --- RETURN CACHED DATA --- # --- RETURN CACHED DATA ---
if cached_data and (now - last_fetch_time < CACHE_TTL): if cached_data and (now - last_fetch_time < CACHE_TTL):
print("⚡ Returning cached data") print("⚡ Returning cached data")
+4 -2
View File
@@ -1,7 +1,9 @@
services: services:
garmin-api: garmin-api:
build: . build:
container_name: garmin context: .
dockerfile: Dockerfile
container_name: garmin-api
ports: ports:
- "5000:5000" - "5000:5000"
env_file: env_file: