From f0b1054861f0089d8879609a9c9ff27b12caa6ba Mon Sep 17 00:00:00 2001 From: Benedikt Schwering Date: Fri, 3 May 2024 16:18:04 +0200 Subject: [PATCH] fix(atoss): avoid timeout --- api/src/atoss.py | 12 ++++++------ api/src/models.py | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/api/src/atoss.py b/api/src/atoss.py index 1236184..9e4efd8 100644 --- a/api/src/atoss.py +++ b/api/src/atoss.py @@ -16,7 +16,7 @@ 'Gleitzeit', ] -def __init_session() -> Session: +def init_session() -> Session: init_response = requests.get( url=__init_url, ) @@ -40,6 +40,7 @@ def __init_session() -> Session: for option in init_response.text.splitlines() if option.startswith('[\'zul.sel.Option\'') and 'value' in option }, + cookies=init_response.cookies.get_dict(), ) def __call(session: Session, *arguments: CallItem) -> ResponseDto: @@ -59,6 +60,7 @@ def __call(session: Session, *arguments: CallItem) -> ResponseDto: ), ), }, + cookies=session.cookies, ) if 'Kombination Personalnummer / PIN-Code falsch' in call_response.text: @@ -101,9 +103,9 @@ def __call(session: Session, *arguments: CallItem) -> ResponseDto: flexi_balance=response['Gleitzeit'], ) -def get_balance(personal_number: str, pin: str) -> ResponseDto: +def get_balance(personal_number: str, pin: str, session: Session = init_session()) -> ResponseDto: return __call( - __init_session(), + session, CallItem( command=CommandEnum.on_change, uuid='badgeno', @@ -124,9 +126,7 @@ def get_balance(personal_number: str, pin: str) -> ResponseDto: ), ) -def post_booking(personal_number: str, pin: str, action: ActionEnum, type: TypeEnum) -> dict: - session = __init_session() - +def post_booking(personal_number: str, pin: str, action: ActionEnum, type: TypeEnum, session: Session = init_session()) -> dict: return __call( session, CallItem( diff --git a/api/src/models.py b/api/src/models.py index 42524c4..457ca52 100644 --- a/api/src/models.py +++ b/api/src/models.py @@ -6,6 +6,7 @@ class Session(BaseModel): jsession: str dt: str selection_uuids: dict + cookies: dict class CommandEnum(str, Enum): on_change = 'onChange'