Skip to content
Snippets Groups Projects
Commit fc9a8712 authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Clean up a little

parent 8dcb60a7
No related branches found
No related tags found
No related merge requests found
...@@ -160,6 +160,19 @@ def midinumber_to_hertz(note: int) -> float: ...@@ -160,6 +160,19 @@ def midinumber_to_hertz(note: int) -> float:
return (440 / 32) * (2 ** ((note - 9) / 12)) return (440 / 32) * (2 ** ((note - 9) / 12))
def build_url(config, endpoint: str = "") -> str:
"""
Build a URL for requests
"""
if config["server"]["port"] == 80:
protocol = "http"
else:
protocol = "https"
url = '{}://{}/{}'.format(protocol, config["server"]["address"].rstrip("/"), endpoint.lstrip("/"))
return url
def process_request(output_queue, config=None, logger=None): def process_request(output_queue, config=None, logger=None):
""" """
Process a event from the output queue. Process a event from the output queue.
...@@ -181,12 +194,7 @@ def process_request(output_queue, config=None, logger=None): ...@@ -181,12 +194,7 @@ def process_request(output_queue, config=None, logger=None):
dispatch_led("failure", config) dispatch_led("failure", config)
dispatch_buzzer("failure", config) dispatch_buzzer("failure", config)
elif response == "error": elif response == "error":
if config["server"]["port"] == 80: url = build_url(config, "/alive")
protocol = "http"
else:
protocol = "https"
url = '{}://{}/alive'.format(protocol, config["server"]["address"].rstrip("/"))
reached = False reached = False
attempts = 1 attempts = 1
# Display the fitting LED color for the state at the given repetition # Display the fitting LED color for the state at the given repetition
...@@ -204,6 +212,7 @@ def process_request(output_queue, config=None, logger=None): ...@@ -204,6 +212,7 @@ def process_request(output_queue, config=None, logger=None):
logger.warn("Didn't reach server at {} for {} attempts: ".format(url, attempts, e)) logger.warn("Didn't reach server at {} for {} attempts: ".format(url, attempts, e))
attempts += 1 attempts += 1
time.sleep(6) time.sleep(6)
else: else:
time.sleep(0.01) time.sleep(0.01)
...@@ -381,12 +390,7 @@ def update_id_patterns(config, logger) -> 'Config': ...@@ -381,12 +390,7 @@ def update_id_patterns(config, logger) -> 'Config':
""" """
Update the id_patterns from the server via http Update the id_patterns from the server via http
""" """
if config["server"]["port"] == 80: url = build_url(config, "/config/database/id_patterns")
protocol = "http"
else:
protocol = "https"
url = '{}://{}/config/database/id_patterns'.format(protocol, config["server"]["address"].rstrip("/"))
logger.debug("Requesting id_pattern update at address: {}".format(url)) logger.debug("Requesting id_pattern update at address: {}".format(url))
# Send request # Send request
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment