From 19f641a1a61d14dd527eb2aac3814188ee832a9e Mon Sep 17 00:00:00 2001 From: Samuel Jones Date: Mon, 8 Jun 2026 21:23:36 +0100 Subject: [PATCH] Migration to template.html and tweaks to design. --- media/template.html | 65 +++++++++++++++++++++++++++++++++++++++++ src/fares_site/serve.py | 47 ++++------------------------- 2 files changed, 70 insertions(+), 42 deletions(-) create mode 100644 media/template.html diff --git a/media/template.html b/media/template.html new file mode 100644 index 0000000..f0a1dcc --- /dev/null +++ b/media/template.html @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + +
+ +
+ + + + + +
+ + + Ballast-Data Product | + Contact: Non-Doxxing Email Lorum Ipsum
+ Some Header Content +
+
+ +
+ +
+ +
+
+ + Fares
+
+ +
+ + + +
+ +
+ +
+ Open Rail Data Disclaimer Etc. | No Guarantees or Whatever | We do freelance and dont want to be poor. +
+
+ + diff --git a/src/fares_site/serve.py b/src/fares_site/serve.py index be75e98..fb106b9 100644 --- a/src/fares_site/serve.py +++ b/src/fares_site/serve.py @@ -7,7 +7,7 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from logging import INFO, Logger import pandas as pd -from pandas.io.formats.style import Styler +from pathlib import Path from requests.exceptions import ConnectionError from fares_site.api_calling import fares_query @@ -35,45 +35,7 @@ COLUMN_RENAMES = { "restriction_code": "Restriction", } -HTML_CONTENT_HEADER = """ - - - - - - - - - - - -
-
-Ballast-Data Product
-Contact: Non-Doxxing Email Lorum Ipsum
-Some Header Content -
-
-
- -
-
- - Fares
-
-
-""" - -HTML_CONTENT_FOOTER = """ -
-
-
-Open Rail Data Disclaimer Etc. | No Guarantees or Whatever | We do freelance and dont want to be poor. -
-
- - -""" +DEFAULT_TEMPLATE_PATH = Path(__file__).parents[2] / "media/template.html" logger: Logger = Logger(name=__name__, level=INFO) @@ -87,7 +49,7 @@ class FaresHandler(BaseHTTPRequestHandler): text = text[1] return {s.split("=")[0]: s.split("=")[-1] for s in text.split("&")} - def content_of_GET(self) -> str: + def content_of_GET(self, template_path: Path = DEFAULT_TEMPLATE_PATH) -> str: """ Generates the content of a GET request. Responsible for receiving the requests' details and constructing the output. @@ -122,7 +84,8 @@ class FaresHandler(BaseHTTPRequestHandler): text += fares_table.to_html() text += " \n " text += "" - return HTML_CONTENT_HEADER + text + HTML_CONTENT_FOOTER + with open(template_path, "r") as rf: + return rf.read().replace("", text) def do_GET(self) -> None: """