fix: save date correctly

This commit is contained in:
Lunaresk 2021-12-04 10:50:20 +01:00
parent 60661ce2ec
commit 8504ccdf1a
2 changed files with 17 additions and 7 deletions

View File

@ -37,9 +37,9 @@ def send_scan(login: str, scanned: dict[int: int], date:str = None):
if date: if date:
infos['date'] = date infos['date'] = date
try: try:
response = put(url=":".join([SERVER, str( response = post(url=":".join([SERVER, str(
PORT)]) + '/scan2kasse/insert', json=infos) 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: except Exception as e:
LOGGER.exception(e) LOGGER.exception(e)
return infos return infos

View File

@ -34,12 +34,14 @@ def main() -> None:
if login == "quit": if login == "quit":
break break
if not connection.check_login(login): if not connection.check_login(login):
LOGGER.debug("Login failed")
continue # Send Error that login wasn't possible continue # Send Error that login wasn't possible
LOGGER.debug("Login successful")
scanned = scanning() scanned = scanning()
scanned = group_scanning(scanned) scanned = group_scanning(scanned)
result = connection.send_scan(login, scanned) result = connection.send_scan(login, scanned)
if result != True: if result != True:
result['date'] = str(date.now()) result['date'] = str(date.today())
TEMP.append(result) TEMP.append(result)
if TEMP: if TEMP:
for bought in TEMP: for bought in TEMP:
@ -51,6 +53,7 @@ def main() -> None:
jdump(TEMP, file) jdump(TEMP, file)
elif exists(TEMPFILE): elif exists(TEMPFILE):
remove(TEMPFILE) remove(TEMPFILE)
LOGGER.info(TEMP)
def scanning() -> list: def scanning() -> list:
@ -69,6 +72,13 @@ def scanning() -> list:
if not i: if not i:
break # send a short timeout message before break break # send a short timeout message before break
scan = stdin.readline().strip() scan = stdin.readline().strip()
match scan:
case "delete":
try:
scanned.pop()
except IndexError as e:
LOGGER.exception(e)
case _:
try: try:
scanned.remove(scan) scanned.remove(scan)
except ValueError as e: except ValueError as e: