- New gomag_client.py service: async httpx client that downloads orders from GoMag API with full pagination and 1s rate-limit sleep - config.py: add GOMAG_API_KEY, GOMAG_API_SHOP, GOMAG_ORDER_DAYS_BACK, GOMAG_LIMIT, GOMAG_API_URL settings - sync_service.py: Phase 0 downloads fresh orders before reading JSONs; graceful skip if API keys not configured - start.sh: auto-detect INSTANTCLIENTPATH from .env, fallback to thin mode - .env.example: document GoMag API variables Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
from pydantic_settings import BaseSettings
|
|
from pydantic import model_validator
|
|
from pathlib import Path
|
|
import os
|
|
|
|
# Anchored paths - independent of CWD
|
|
_api_root = Path(__file__).resolve().parent.parent # .../gomag/api/
|
|
_project_root = _api_root.parent # .../gomag/
|
|
_env_path = _api_root / ".env"
|
|
|
|
class Settings(BaseSettings):
|
|
# Oracle
|
|
ORACLE_USER: str = "MARIUSM_AUTO"
|
|
ORACLE_PASSWORD: str = "ROMFASTSOFT"
|
|
ORACLE_DSN: str = "ROA_CENTRAL"
|
|
INSTANTCLIENTPATH: str = ""
|
|
FORCE_THIN_MODE: bool = False
|
|
TNS_ADMIN: str = ""
|
|
|
|
# SQLite
|
|
SQLITE_DB_PATH: str = "data/import.db"
|
|
|
|
# App
|
|
APP_PORT: int = 5003
|
|
LOG_LEVEL: str = "INFO"
|
|
JSON_OUTPUT_DIR: str = "output"
|
|
|
|
# SMTP (optional)
|
|
SMTP_HOST: str = ""
|
|
SMTP_PORT: int = 587
|
|
SMTP_USER: str = ""
|
|
SMTP_PASSWORD: str = ""
|
|
SMTP_TO: str = ""
|
|
|
|
# Auth (optional)
|
|
API_USERNAME: str = ""
|
|
API_PASSWORD: str = ""
|
|
|
|
# ROA Import Settings
|
|
ID_POL: int = 0
|
|
ID_GESTIUNE: int = 0
|
|
ID_SECTIE: int = 0
|
|
|
|
# GoMag API
|
|
GOMAG_API_KEY: str = ""
|
|
GOMAG_API_SHOP: str = ""
|
|
GOMAG_ORDER_DAYS_BACK: int = 7
|
|
GOMAG_LIMIT: int = 100
|
|
GOMAG_API_URL: str = "https://api.gomag.ro/api/v1/order/read/json"
|
|
|
|
@model_validator(mode="after")
|
|
def resolve_paths(self):
|
|
"""Resolve relative paths against known roots, independent of CWD."""
|
|
# SQLITE_DB_PATH: relative to api/ root
|
|
if self.SQLITE_DB_PATH and not os.path.isabs(self.SQLITE_DB_PATH):
|
|
self.SQLITE_DB_PATH = str(_api_root / self.SQLITE_DB_PATH)
|
|
# JSON_OUTPUT_DIR: relative to project root
|
|
if self.JSON_OUTPUT_DIR and not os.path.isabs(self.JSON_OUTPUT_DIR):
|
|
self.JSON_OUTPUT_DIR = str(_project_root / self.JSON_OUTPUT_DIR)
|
|
return self
|
|
|
|
model_config = {"env_file": str(_env_path), "env_file_encoding": "utf-8", "extra": "ignore"}
|
|
|
|
settings = Settings()
|