From 8504ccdf1a97168b1d877dd95ba7562222a39d95 Mon Sep 17 00:00:00 2001 From: Lunaresk Date: Sat, 4 Dec 2021 10:50:20 +0100 Subject: [PATCH] fix: save date correctly --- client/src/connection.py | 4 ++-- client/src/main.py | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/client/src/connection.py b/client/src/connection.py index ac3a054..caa1927 100644 --- a/client/src/connection.py +++ b/client/src/connection.py @@ -37,9 +37,9 @@ def send_scan(login: str, scanned: dict[int: int], date:str = None): if date: infos['date'] = date try: - response = put(url=":".join([SERVER, str( + response = post(url=":".join([SERVER, str( PORT)]) + '/scan2kasse/insert', json=infos) - return True if response.status_code == 201 else response.json + return True if response.status_code == 201 else response.json() except Exception as e: LOGGER.exception(e) return infos diff --git a/client/src/main.py b/client/src/main.py index 560d0eb..076e925 100644 --- a/client/src/main.py +++ b/client/src/main.py @@ -34,12 +34,14 @@ def main() -> None: if login == "quit": break if not connection.check_login(login): + LOGGER.debug("Login failed") continue # Send Error that login wasn't possible + LOGGER.debug("Login successful") scanned = scanning() scanned = group_scanning(scanned) result = connection.send_scan(login, scanned) if result != True: - result['date'] = str(date.now()) + result['date'] = str(date.today()) TEMP.append(result) if TEMP: for bought in TEMP: @@ -51,6 +53,7 @@ def main() -> None: jdump(TEMP, file) elif exists(TEMPFILE): remove(TEMPFILE) + LOGGER.info(TEMP) def scanning() -> list: @@ -69,10 +72,17 @@ def scanning() -> list: if not i: break # send a short timeout message before break scan = stdin.readline().strip() - try: - scanned.remove(scan) - except ValueError as e: - LOGGER.exception(e) + match scan: + case "delete": + try: + scanned.pop() + except IndexError as e: + LOGGER.exception(e) + case _: + try: + scanned.remove(scan) + except ValueError as e: + LOGGER.exception(e) case _: scanned.append(scan) return scanned