From 850f320c88338d07d6d2eb6a7543132250fb2a74 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Mon, 19 Feb 2024 19:36:37 +0000 Subject: [PATCH] Lint and improve status CGI script --- themes/lhs-retro/static/cgi/status.cgi | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/themes/lhs-retro/static/cgi/status.cgi b/themes/lhs-retro/static/cgi/status.cgi index 895ea8a..63079bd 100755 --- a/themes/lhs-retro/static/cgi/status.cgi +++ b/themes/lhs-retro/static/cgi/status.cgi @@ -5,20 +5,21 @@ import sys def main(output=sys.stdout): - output.write('Content-Type: text/html\n\n') + output.write("Content-Type: text/html\n\n") try: - resp = requests.get('https://api.leighhack.org/space.json') + resp = requests.get("https://api.leighhack.org/space.json", timeout=3) if resp.ok: data = resp.json() - if 'state' in data: - if data['state']['open']: - output.write('Open') - return + if "state" in data and data["state"]["open"]: + output.write("Open") + return except Exception: pass - output.write('Closed') + # If we have a HTTP error, exception, then just assume we're closed. + output.write("Closed") -if __name__ == '__main__': + +if __name__ == "__main__": main()