diff --git a/client/src/config.yaml.template b/client/src/config.yaml.template index 5121e20..b2fef8d 100644 --- a/client/src/config.yaml.template +++ b/client/src/config.yaml.template @@ -4,4 +4,8 @@ server: options: barcode: - codeid_position: Null \ No newline at end of file + codeid: + position: Null + Code128: "A" + EAN8: "C" + EAN13: "D" \ No newline at end of file diff --git a/client/src/connection.py b/client/src/connection.py index 7626a1d..8b01b15 100644 --- a/client/src/connection.py +++ b/client/src/connection.py @@ -27,9 +27,9 @@ del(data) def check_login(login: str) -> bool: try: - response = get(url=":".join([SERVER, str(PORT)]) + '/scan2kasse/login', json={'login': login}) + response = get(url=":".join([SERVER, str(PORT)]) + '/scan2kasse/login', json={'login': login}, timeout=1) except Exception as e: - LOGGER.exception(e) + LOGGER.debug("Server not reachable.") return False else: if response.status_code == 200: @@ -43,8 +43,8 @@ def send_scan(user: str, scanned: dict[int: int], date:str = None): infos['date'] = date try: response = post(url=":".join([SERVER, str( - PORT)]) + '/scan2kasse/insert', json=infos) + PORT)]) + '/scan2kasse/insert', json=infos, timeout=1) return True if response.status_code == 201 else response.json() except Exception as e: - LOGGER.exception(e) + LOGGER.exception() return infos diff --git a/client/src/main.py b/client/src/main.py index f1c9b5d..63c70d9 100644 --- a/client/src/main.py +++ b/client/src/main.py @@ -29,7 +29,10 @@ LOGGER.addHandler(consoleHandler) with open("config.yaml", 'r') as file: data = safe_load(file)['options'] -CODEID_POS = data['barcode']['codeid_position'] +CODEID_POS = data['barcode']['codeid']['position'] if data and 'barcode' in data and 'codeid' in data['barcode'] and 'position' in data['barcode']['codeid'] else None +CODE128 = data['barcode']['codeid']['Code128'] if data and 'barcode' in data and 'codeid' in data['barcode'] and 'Code128' in data['barcode']['codeid'] else "A" +EAN8 = data['barcode']['codeid']['EAN8'] if data and 'barcode' in data and 'codeid' in data['barcode'] and 'EAN8' in data['barcode']['codeid'] else "C" +EAN13 = data['barcode']['codeid']['EAN13'] if data and 'barcode' in data and 'codeid' in data['barcode'] and 'EAN13' in data['barcode']['codeid'] else "D" TEMPFILE = "scans.json" @@ -51,18 +54,18 @@ def delete(scanned: list): if not i: return #TODO send a short timeout message before return scan = stdin.readline().strip() - codeid, scan = split_codeid(scan, "A") + codeid, scan = split_codeid(scan, "") match scan: case "delete": try: scanned.pop() except IndexError as e: - LOGGER.exception(e) + LOGGER.exception() case _: try: scanned.remove(scan) except ValueError as e: - LOGGER.exception(e) + LOGGER.exception() def group_scanning(scanned: list[int]) -> dict[int: int]: scan_dict = {} @@ -93,10 +96,10 @@ def group_temp(TEMP: list): def login(user: str = None): if not user: user = input("Enter Login: ") - codeid, user = split_codeid(user, "D") + codeid, user = split_codeid(user, CODE128) else: - codeid = "D" - if codeid != "D": + codeid = CODE128 + if codeid != CODE128: return None if not connection.check_login(user): LOGGER.debug("Login failed") @@ -114,9 +117,11 @@ def scanning(user: str) -> dict[int: int]: scan = stdin.readline().strip() codeid, scan = split_codeid(scan, "A") match codeid: - case "A": + case str(EAN8): scanned.append(scan) - case "D": + case str(EAN13): + scanned.append(scan) + case str(CODE128): match scan: case "logout": break diff --git a/server/src/database.py b/server/src/database.py index 19533d3..19c2594 100644 --- a/server/src/database.py +++ b/server/src/database.py @@ -66,9 +66,9 @@ class Database: try: result = cursor.fetchall() except ProgrammingError as e: - LOGGER.exception(e) + LOGGER.exception() except Exception as e: - LOGGER.exception(e) + LOGGER.exception() return result @connectionpersistence @@ -97,9 +97,9 @@ class Database: try: result = cursor.fetchall() except ProgrammingError as e: - LOGGER.exception(e) + LOGGER.exception() except Exception as e: - LOGGER.exception(e) + LOGGER.exception() return result @connectionpersistence @@ -125,9 +125,9 @@ class Database: failed = {'user': user, 'items': {value['item']: value['amount']}} if date: failed['date'] = date - LOGGER.exception(e) + LOGGER.exception() except Exception as e: - LOGGER.exception(e) + LOGGER.exception() return failed def __delete__(self):