From c17ed59e85f9579e45f1c59d3c95268a1f7d361b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 7 Jun 2023 22:49:49 +0000 Subject: cleanup --- helpers.py | 2 +- server.py | 29 ++++++----------------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/helpers.py b/helpers.py index 843d257..02f4493 100644 --- a/helpers.py +++ b/helpers.py @@ -57,7 +57,7 @@ def veljavnost(registrska: str, drzava: str): } print("\n", payload, "\n------------------\n\n\n") r = requests.post(purl, json=payload, headers=get_headers(), verify=False) - # print("\n"+r.text+"\n------------------\n\n\n") + print("\n"+r.text+"\n------------------\n\n\n") print(r.status_code, r.reason, r.url) return r.json() diff --git a/server.py b/server.py index 893acb3..e7b5bc3 100644 --- a/server.py +++ b/server.py @@ -73,47 +73,30 @@ def static_from_root(): return send_from_directory(app.static_folder, request.path[1:]) +@app.route("/global", methods=["POST"]) @app.route("/", methods=["POST"]) def apcall(): if "headers" in request.form: setHeaders(request) return "OK" registrska = request.form["registrska"] - try: - ar = aux(registrska) - app.logger.info( - f'Registrska "{registrska}" je veljavna do {ar} ob {niceTime()}' - ) - # discordLog(f"Registrska \"{registrska}\" je veljavna do {ar} ob {niceTime()}") - return render_template("index.html", valid_until=ar, license_plate=registrska) - except Exception as e: - spamDiscord(str(e)) - app.logger.error(f"\nNapaka pri {registrska} ob {niceTime()}") - # discordLog(f"!!!!!!!!!!!!!!!!!!!!!!!!!!!\nNapaka pri {registrska} ob {niceTime()}") - return render_template("failure.html") - - -@app.route("/global", methods=["POST"]) -def apcall_global(): - print(request.form) - registrska = request.form["registrska"] - drzava = request.form["drzava"] + drzava = request.form.get("drzava", "SI") try: ar = aux(registrska, drzava) app.logger.info( f'Registrska "{registrska}" je veljavna do {ar} ob {niceTime()}' ) # discordLog(f"Registrska \"{registrska}\" je veljavna do {ar} ob {niceTime()}") - return render_template( - "index_global.html", valid_until=ar, license_plate=registrska - ) + user_language = request.accept_languages.best_match(["sl", "en"]) + if user_language == "en": + return render_template("index_global.html", valid_until=ar, license_plate=registrska) + return render_template("index.html", valid_until=ar, license_plate=registrska) except Exception as e: spamDiscord(str(e)) app.logger.error(f"\nNapaka pri {registrska} ob {niceTime()}") # discordLog(f"!!!!!!!!!!!!!!!!!!!!!!!!!!!\nNapaka pri {registrska} ob {niceTime()}") return render_template("failure.html") - @app.route("/", methods=["GET"]) def index(): user_language = request.accept_languages.best_match(["sl", "en"]) -- cgit v1.2.3