41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import signal
|
|
import sys
|
|
import os
|
|
import logger
|
|
from server import Server
|
|
|
|
def _handle_exit(sig, frame):
|
|
print("Exiting...")
|
|
sys.exit(0)
|
|
|
|
def _get_environment_variable(key: str) -> str:
|
|
value = os.getenv(key)
|
|
|
|
if not value:
|
|
logger.error("Environment variable '" + key + "' must be set")
|
|
|
|
return value
|
|
|
|
def _parse_environment_variable(key: str, value: str) -> int | None:
|
|
try:
|
|
return int(value)
|
|
except ValueError:
|
|
logger.error("Environment variable '" + key + "' must be an integer")
|
|
|
|
def main():
|
|
signal.signal(signal.SIGTERM, _handle_exit)
|
|
signal.signal(signal.SIGINT, _handle_exit)
|
|
|
|
host = _get_environment_variable("HOST")
|
|
port = _get_environment_variable("PORT")
|
|
cache_duration = _get_environment_variable("CACHE_DURATION")
|
|
ics_url = _get_environment_variable("ICS_URL")
|
|
|
|
port_int = _parse_environment_variable("PORT", port)
|
|
cache_duration_int = _parse_environment_variable("CACHE_DURATION", cache_duration)
|
|
|
|
server = Server(host, port_int, cache_duration_int, ics_url)
|
|
server.serve()
|
|
|
|
if __name__ == "__main__":
|
|
main() |