added test mode and adapted for docker
This commit is contained in:
+4
-7
@@ -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"]
|
||||||
|
|||||||
@@ -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")
|
||||||
@@ -136,4 +142,4 @@ def get_image():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=5000)
|
app.run(host='0.0.0.0', port=5000)
|
||||||
+5
-3
@@ -1,9 +1,11 @@
|
|||||||
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:
|
||||||
- .env
|
- .env
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
Reference in New Issue
Block a user