From 90e19a89ee2cddab2b504b1bc3902f2edf63e954 Mon Sep 17 00:00:00 2001 From: David Trattnig <david.trattnig@o94.at> Date: Thu, 12 Mar 2020 19:32:04 +0100 Subject: [PATCH] Small, custom template engine. --- api.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/api.py b/api.py index 7e8a268b..da192582 100644 --- a/api.py +++ b/api.py @@ -89,7 +89,7 @@ class EngineApi: api = None logger = None - trackservice_schema = None + # trackservice_schema = None def __init__(self, config, api): @@ -145,6 +145,31 @@ class EngineApi: # self.logger.info(spec.to_yaml()) + def generate_html(self): + """ + Generates HTML based on the configuration options and templates. + """ + template = open("web/templates/clock.html", "r") + html = open("web/clock.html", "w") + + config_options = { + "CONFIG-STATION-NAME": config.station_name, + "CONFIG-STATION-LOGO-URL": config.station_logo_url, + "CONFIG-STATION-LOGO-SIZE": config.station_logo_size, + "CONFIG-API-URL": config.exposed_api_url + } + + content = template.read() + + for key, value in config_options.items(): + content = content.replace(":::"+key+":::", value) + + html.write(content) + template.close() + html.close() + + + def run(self): """ Starts the API server. @@ -387,6 +412,7 @@ class ReportResource(Resource): if __name__ == "__main__": engine_api = EngineApi(config, api) + engine_api.generate_html() engine_api.run() \ No newline at end of file -- GitLab