added error handling in registrace.py
This commit is contained in:
parent
52d81c127d
commit
9deda461ee
@ -1,6 +1,6 @@
|
||||
{
|
||||
"station_id": "1",
|
||||
"host": "https://beta.quarda.cz",
|
||||
"host": "https://beta.alkator.cz",
|
||||
"login": "station_register@alkator.cz",
|
||||
"password": "password_heslo"
|
||||
}
|
@ -10,6 +10,7 @@ import json
|
||||
|
||||
gi.require_version('Gtk', '4.0')
|
||||
from gi.repository import Gtk, Gio, Gdk
|
||||
from requests.adapters import HTTPAdapter, Retry
|
||||
|
||||
activeCards = []
|
||||
|
||||
@ -28,6 +29,15 @@ with open('config.json', 'r') as f:
|
||||
config = json.load(f)
|
||||
|
||||
session = requests.Session()
|
||||
|
||||
|
||||
retries = Retry(total=10,
|
||||
backoff_factor=1,
|
||||
status_forcelist=[ 500, 502, 503, 504 ])
|
||||
|
||||
session.mount('https://', HTTPAdapter(max_retries=retries))
|
||||
|
||||
|
||||
session.post(config['host'] + '/api/login', {'email':config['login'], 'password': config['password']})
|
||||
|
||||
def refreshDb():
|
||||
|
@ -6,6 +6,8 @@ import usb.core
|
||||
import usb.util
|
||||
from PyQt6 import QtWidgets, uic, QtGui
|
||||
|
||||
from requests.adapters import HTTPAdapter, Retry
|
||||
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
|
||||
TIME = 600
|
||||
@ -22,6 +24,13 @@ session = requests.Session()
|
||||
session.post(config['host'] + '/api/login', {'email':config['login'], 'password': config['password']})
|
||||
|
||||
|
||||
retries = Retry(total=3,
|
||||
backoff_factor=1,
|
||||
status_forcelist=[ 500, 502, 503, 504 ],)
|
||||
|
||||
session.mount('https://', HTTPAdapter(max_retries=retries))
|
||||
|
||||
|
||||
last_card = 0
|
||||
last_time = datetime.datetime.now()
|
||||
|
||||
@ -41,13 +50,21 @@ def register_racer():
|
||||
raise
|
||||
|
||||
response = session.post(config['host'] + '/api/card/register', json={'racer_id': racer_id, 'starting_number': starting_number, 'card_id': card_id})
|
||||
if response.status_code == 400:
|
||||
mb = QtWidgets.QMessageBox(text="Zaregistrování selhalo! Je špatně vyplněné startovní číslo nebo karta už je přiřazená k jinému závodníku.")
|
||||
mb.exec()
|
||||
return
|
||||
if response.status_code != 200:
|
||||
raise Exception(response.status_code, response.content)
|
||||
mb = QtWidgets.QMessageBox(text="Neznámá chyba!")
|
||||
mb.exec()
|
||||
return
|
||||
|
||||
racer = list(filter(lambda x: x['racer_id'] == racer_id, racers))[0]
|
||||
racer['card_id'] = card_id
|
||||
racer['starting_number'] = starting_number
|
||||
updateRacers()
|
||||
mb = QtWidgets.QMessageBox(text="Úspěšné zaregistrování závodníka!")
|
||||
mb.exec()
|
||||
|
||||
|
||||
def unregister_racer():
|
||||
@ -55,7 +72,10 @@ def unregister_racer():
|
||||
time = last_time
|
||||
|
||||
response = session.post(config['host'] + '/api/station/register', json={'card_id': card_id, 'time': time.strftime('%d.%m.%Y %H:%M:%S.%f'), 'station_id': config['station_id']})
|
||||
assert response.status_code == 200
|
||||
if response != 200:
|
||||
mb = QtWidgets.QMessageBox(text="Selhalo zapsání na Stanici!")
|
||||
mb.exec()
|
||||
return
|
||||
|
||||
racer = list(filter(lambda x: x['card_id'] == card_id, racers))[0]
|
||||
starting_number = racer['starting_number']
|
||||
@ -64,7 +84,16 @@ def unregister_racer():
|
||||
|
||||
response = session.post(config['host'] + '/api/card/unregister', json={'racer_id': racer_id, 'starting_number': starting_number, 'card_id': card_id})
|
||||
|
||||
assert response.status_code == 200
|
||||
if response.status_code != 200:
|
||||
mb = QtWidgets.QMessageBox(text="Registrace na stanici proběhla úspěšně, ale karta nebyla odhlášena!")
|
||||
mb.exec()
|
||||
return
|
||||
|
||||
json = response.json()
|
||||
|
||||
mb = QtWidgets.QMessageBox(text=f"Úspěšné odhlášení závodníka! Finální čas je: {json['time']}")
|
||||
mb.exec()
|
||||
|
||||
|
||||
|
||||
window = uic.loadUi("registrace.ui")
|
||||
|
Loading…
x
Reference in New Issue
Block a user