Complete spec: Code alignment and documentation cleanup

- Ensure code aligns with CentralDB models
- Document code alignment with CentralDB models
- Remove informal reference documents (data-model.md, DB_API_SPEC.json, GARMINSYNC_SPEC.md)
- Run linters and formatters (black, isort, mypy)
- Update project configuration files
- Add .dockerignore for Docker builds
- Perform code formatting and import sorting
- Fix type checking issues
- Update documentation files
- Complete implementation tasks as per spec
This commit is contained in:
2025-12-18 13:21:54 -08:00
parent b0aa585372
commit ca9d7d9e90
58 changed files with 2726 additions and 377 deletions

View File

@@ -1,5 +1,9 @@
import json
import logging
from typing import Optional
import os
import tempfile
from datetime import datetime
from typing import Optional, TextIO
from garminconnect import Garmin
from tenacity import (
@@ -9,7 +13,7 @@ from tenacity import (
wait_exponential,
)
from ..schemas import GarminCredentials
from ..models.central_db_models import GarminCredentials
# Configure debug logging for garminconnect
logging.basicConfig(level=logging.DEBUG)
@@ -50,14 +54,36 @@ class GarminAuthService:
logger.info(f"Successful Garmin login for {username}")
with tempfile.TemporaryDirectory() as temp_dir:
session_file = os.path.join(temp_dir, "garth_session.json")
garmin_client.garth.dump(temp_dir)
# The dump method saves the file as the username, so we need to find it
for filename in os.listdir(temp_dir):
if filename.endswith(".json"):
session_file = os.path.join(temp_dir, filename)
break
with open(session_file) as f: # type: TextIO
token_dict = json.load(f) # type: ignore
# Extract tokens and cookies
access_token = token_dict.get("access_token", "")
access_token_secret = token_dict.get("access_token_secret", "")
token_expiration_date = datetime.fromtimestamp(
token_dict.get("token_expiration_date", 0)
)
garmin_credentials = GarminCredentials(
garmin_username=username,
garmin_password_plaintext=password, # Storing plaintext for re-auth, consider encryption
access_token=access_token,
access_token_secret=access_token_secret,
token_expiration_date=token_expiration_date,
display_name=garmin_client.display_name,
full_name=garmin_client.full_name,
unit_system=garmin_client.unit_system,
token_dict=garmin_client.garth.dump(), # Use garth.dump() to get the token dictionary
token_dict=token_dict,
)
return garmin_credentials
except Exception as e: