fix: code-ids set correctly
This commit is contained in:
parent
a0c463d466
commit
f37cfbdaaa
@ -4,4 +4,8 @@ server:
|
|||||||
|
|
||||||
options:
|
options:
|
||||||
barcode:
|
barcode:
|
||||||
codeid_position: Null
|
codeid:
|
||||||
|
position: Null
|
||||||
|
Code128: "A"
|
||||||
|
EAN8: "C"
|
||||||
|
EAN13: "D"
|
||||||
@ -27,9 +27,9 @@ del(data)
|
|||||||
|
|
||||||
def check_login(login: str) -> bool:
|
def check_login(login: str) -> bool:
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
LOGGER.exception(e)
|
LOGGER.debug("Server not reachable.")
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
@ -43,8 +43,8 @@ def send_scan(user: str, scanned: dict[int: int], date:str = None):
|
|||||||
infos['date'] = date
|
infos['date'] = date
|
||||||
try:
|
try:
|
||||||
response = post(url=":".join([SERVER, str(
|
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()
|
return True if response.status_code == 201 else response.json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOGGER.exception(e)
|
LOGGER.exception()
|
||||||
return infos
|
return infos
|
||||||
|
|||||||
@ -29,7 +29,10 @@ LOGGER.addHandler(consoleHandler)
|
|||||||
|
|
||||||
with open("config.yaml", 'r') as file:
|
with open("config.yaml", 'r') as file:
|
||||||
data = safe_load(file)['options']
|
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"
|
TEMPFILE = "scans.json"
|
||||||
|
|
||||||
@ -51,18 +54,18 @@ def delete(scanned: list):
|
|||||||
if not i:
|
if not i:
|
||||||
return #TODO send a short timeout message before return
|
return #TODO send a short timeout message before return
|
||||||
scan = stdin.readline().strip()
|
scan = stdin.readline().strip()
|
||||||
codeid, scan = split_codeid(scan, "A")
|
codeid, scan = split_codeid(scan, "")
|
||||||
match scan:
|
match scan:
|
||||||
case "delete":
|
case "delete":
|
||||||
try:
|
try:
|
||||||
scanned.pop()
|
scanned.pop()
|
||||||
except IndexError as e:
|
except IndexError as e:
|
||||||
LOGGER.exception(e)
|
LOGGER.exception()
|
||||||
case _:
|
case _:
|
||||||
try:
|
try:
|
||||||
scanned.remove(scan)
|
scanned.remove(scan)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
LOGGER.exception(e)
|
LOGGER.exception()
|
||||||
|
|
||||||
def group_scanning(scanned: list[int]) -> dict[int: int]:
|
def group_scanning(scanned: list[int]) -> dict[int: int]:
|
||||||
scan_dict = {}
|
scan_dict = {}
|
||||||
@ -93,10 +96,10 @@ def group_temp(TEMP: list):
|
|||||||
def login(user: str = None):
|
def login(user: str = None):
|
||||||
if not user:
|
if not user:
|
||||||
user = input("Enter Login: ")
|
user = input("Enter Login: ")
|
||||||
codeid, user = split_codeid(user, "D")
|
codeid, user = split_codeid(user, CODE128)
|
||||||
else:
|
else:
|
||||||
codeid = "D"
|
codeid = CODE128
|
||||||
if codeid != "D":
|
if codeid != CODE128:
|
||||||
return None
|
return None
|
||||||
if not connection.check_login(user):
|
if not connection.check_login(user):
|
||||||
LOGGER.debug("Login failed")
|
LOGGER.debug("Login failed")
|
||||||
@ -114,9 +117,11 @@ def scanning(user: str) -> dict[int: int]:
|
|||||||
scan = stdin.readline().strip()
|
scan = stdin.readline().strip()
|
||||||
codeid, scan = split_codeid(scan, "A")
|
codeid, scan = split_codeid(scan, "A")
|
||||||
match codeid:
|
match codeid:
|
||||||
case "A":
|
case str(EAN8):
|
||||||
scanned.append(scan)
|
scanned.append(scan)
|
||||||
case "D":
|
case str(EAN13):
|
||||||
|
scanned.append(scan)
|
||||||
|
case str(CODE128):
|
||||||
match scan:
|
match scan:
|
||||||
case "logout":
|
case "logout":
|
||||||
break
|
break
|
||||||
|
|||||||
@ -66,9 +66,9 @@ class Database:
|
|||||||
try:
|
try:
|
||||||
result = cursor.fetchall()
|
result = cursor.fetchall()
|
||||||
except ProgrammingError as e:
|
except ProgrammingError as e:
|
||||||
LOGGER.exception(e)
|
LOGGER.exception()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOGGER.exception(e)
|
LOGGER.exception()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@connectionpersistence
|
@connectionpersistence
|
||||||
@ -97,9 +97,9 @@ class Database:
|
|||||||
try:
|
try:
|
||||||
result = cursor.fetchall()
|
result = cursor.fetchall()
|
||||||
except ProgrammingError as e:
|
except ProgrammingError as e:
|
||||||
LOGGER.exception(e)
|
LOGGER.exception()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOGGER.exception(e)
|
LOGGER.exception()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@connectionpersistence
|
@connectionpersistence
|
||||||
@ -125,9 +125,9 @@ class Database:
|
|||||||
failed = {'user': user, 'items': {value['item']: value['amount']}}
|
failed = {'user': user, 'items': {value['item']: value['amount']}}
|
||||||
if date:
|
if date:
|
||||||
failed['date'] = date
|
failed['date'] = date
|
||||||
LOGGER.exception(e)
|
LOGGER.exception()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOGGER.exception(e)
|
LOGGER.exception()
|
||||||
return failed
|
return failed
|
||||||
|
|
||||||
def __delete__(self):
|
def __delete__(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user