Refactoring for reading the config
This commit is contained in:
parent
963ee6b86f
commit
fc11a1e1eb
9 changed files with 264 additions and 166 deletions
|
@ -1,21 +1,50 @@
|
|||
import json
|
||||
import logging.config
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pendulum
|
||||
import yaml
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from resa_padel.models import BookingFilter, Club, User
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
GESTION_SPORTS_URL = "https://toulousepadelclub.gestion-sports.com"
|
||||
USER = os.environ.get("USER")
|
||||
PASSWORD = os.environ.get("PASSWORD")
|
||||
CLUB_ID = os.environ.get("CLUB_ID")
|
||||
_court_ids = os.environ.get("COURT_IDS") or ""
|
||||
COURT_IDS = [int(court_id) for court_id in _court_ids.split(",")] if _court_ids else []
|
||||
SPORT_ID = int(os.environ.get("SPORT_ID"))
|
||||
DATE_TIME = pendulum.parse(os.environ.get("DATE_TIME"))
|
||||
def get_club() -> Club:
|
||||
club_url = os.environ.get("CLUB_URL")
|
||||
court_ids_tmp = os.environ.get("COURT_IDS") or ""
|
||||
court_ids = (
|
||||
[int(court_id) for court_id in court_ids_tmp.split(",")]
|
||||
if court_ids_tmp
|
||||
else []
|
||||
)
|
||||
club_id = os.environ.get("CLUB_ID")
|
||||
return Club(id=club_id, url=club_url, courts_ids=court_ids)
|
||||
|
||||
|
||||
def get_booking_filter() -> BookingFilter:
|
||||
sport_id_tmp = os.environ.get("SPORT_ID")
|
||||
sport_id = int(sport_id_tmp) if sport_id_tmp else None
|
||||
date_time_tmp = os.environ.get("DATE_TIME")
|
||||
date_time = pendulum.parse(date_time_tmp) if date_time_tmp else None
|
||||
return BookingFilter(sport_id=sport_id, date=date_time)
|
||||
|
||||
|
||||
def get_user() -> User:
|
||||
login = os.environ.get("LOGIN")
|
||||
password = os.environ.get("PASSWORD")
|
||||
return User(login=login, password=password)
|
||||
|
||||
|
||||
def get_post_headers(platform_id: str) -> dict:
|
||||
root_path = Path(__file__).parent
|
||||
headers_file = Path(root_path, "resources", platform_id, "post-headers.json")
|
||||
with headers_file.open(mode="r", encoding="utf-8") as f:
|
||||
headers = json.load(f)
|
||||
|
||||
return headers
|
||||
|
||||
|
||||
def init_log_config():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue