Fix parser on SWP dev builds

This commit is contained in:
f4lco
2024-11-17 10:02:15 +01:00
parent afb6ad2593
commit 1bbcd9185a
2 changed files with 15 additions and 2 deletions
+11 -2
View File
@@ -92,14 +92,23 @@ class SWPWebspeiseplanAPI:
req = urllib.request.Request(SWPWebspeiseplanAPI.URL_BASE)
with urllib.request.urlopen(req) as resp:
txt = resp.read().decode("utf-8")
match = re.findall(r"/main.[0-9a-f]+.js", txt)[0]
match = re.findall(r"/main.[0-9a-f]+.js", txt)
if match:
match = match[0]
else:
# Development build made it to production, which does not produce
# JS chunks with cache-busting filenames
match = "/index.js"
SWPWebspeiseplanAPI.logger.debug(
"__parse_token: downloading script %s", match
)
req = urllib.request.Request(f"{SWPWebspeiseplanAPI.URL_BASE}{match}")
with urllib.request.urlopen(req) as resp:
txt = resp.read().decode("utf-8")
proxy_token = re.findall(r"PROXY_TOKEN:\"([0-9a-f]+)\"", txt)[0]
proxy_token =\
re.findall(r"PROXY_TOKEN:\s*[\"']([0-9a-f]+)[\"']", txt)[0]
SWPWebspeiseplanAPI.logger.debug(
"__parse_token: PROXY_TOKEN %s", proxy_token
)
+4
View File
@@ -71,3 +71,7 @@ def canteen_index():
@app.route("/health_check")
def health_check():
return make_response("OK", 200)
if __name__ == '__main__':
app.run()