45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import signal
|
|
import sys
|
|
import os
|
|
import logger
|
|
import utils
|
|
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(f"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(f"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")
|
|
time_zone = _get_environment_variable("TIME_ZONE")
|
|
|
|
port_int = _parse_environment_variable("PORT", port)
|
|
cache_duration_int = _parse_environment_variable("CACHE_DURATION", cache_duration)
|
|
|
|
utils.set_time_zone(time_zone)
|
|
|
|
server = Server(host, port_int, cache_duration_int, ics_url)
|
|
server.serve()
|
|
|
|
if __name__ == "__main__":
|
|
main() |