Migration to template.html and tweaks to design.

This commit is contained in:
2026-06-08 21:23:36 +01:00
parent ad2f9b609b
commit 19f641a1a6
2 changed files with 70 additions and 42 deletions
+65
View File
@@ -0,0 +1,65 @@
<!DOCTYPE HTML>
<html>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Merriweather+Sans:ital,wght@0,300..800;1,300..800&display=swap">
<link rel="stylesheet" href="https://cdn.ballast-data.co.uk/theme.css">
<link rel="icon" type="image/x-icon" href="https://cdn.ballast-data.co.uk/Icon.svg">
<style>
.level0 {
text-align: right;
}
.col0,
.col1,
.col2 {
text-align: left;
}
</style>
</head>
<body style="padding: 0px; margin: 0px;">
<div style="width: 100%; padding: 0px; margin: 0px; background-color: var(--A0);">
<div style="margin-left: auto; margin-right: auto; width: fit-content; background-color: var(--C1); color: var(--A0); margin-top: 0px; padding: 12px; border-radius: 0 0 9px 9px;">
<table>
<tr>
<td>
<img src="https://cdn.ballast-data.co.uk/Icon-NB.svg">
</td>
<td>
Ballast-Data Product |
Contact: Non-Doxxing Email Lorum Ipsum <br>
Some Header Content
</td>
</tr>
</table>
</div>
<br>
<div style="width: fit-content; margin-left: auto; margin-right: auto; border: 9px solid var(--B2); border-radius: 3px; padding: 12px; background-color: white; border-radius: 9px;">
<div style="width: fit-content; margin-left: auto; margin-right: auto; border-bottom: 9px solid var(--C1);">
<br>
<img height=80px src="https://cdn.ballast-data.co.uk/Logo.svg">
<b style="font-size: 4em; line-height: 1; font-weight: 600;"> Fares </b> <br>
</div>
<br>
<!-- Content -->
</div>
<br>
<div style="margin-left: auto; margin-right: auto; width: fit-content; background-color: var(--D1); color: var(--A0); margin-top: 0px; padding: 12px; border-radius: 9px 9px 0 0;">
Open Rail Data Disclaimer Etc. | No Guarantees or Whatever | We do freelance and dont want to be poor.
</div>
</div>
</body>
</html>
+5 -42
View File
@@ -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 = """
<!DOCTYPE HTML>
<html>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Merriweather+Sans:ital,wght@0,300..800;1,300..800&display=swap">
<link rel="stylesheet" href="https://cdn.ballast-data.co.uk/theme.css">
<link rel="icon" type="image/x-icon" href="https://cdn.ballast-data.co.uk/Icon.svg">
</head>
<body style="padding: 0px; margin: 0px;">
<div style="width: 100%; padding: 0px; margin: 0px; background-color: var(--A0);">
<div style="margin-left: auto; margin-right: auto; width: fit-content; background-color: var(--C1); color: var(--A0); margin-top: 0px; padding: 12px; border-radius: 0 0 9px 9px;">
Ballast-Data Product <br>
Contact: Non-Doxxing Email Lorum Ipsum <br>
Some Header Content
</div>
<br>
<div style="width: fit-content; margin-left: auto; margin-right: auto; border: 9px solid var(--B2); border-radius: 3px; padding: 12px; background-color: white; border-radius: 9px;">
<div style="width: fit-content; margin-left: auto; margin-right: auto; border-bottom: 9px solid var(--C1);">
<br>
<img height=80px src="https://cdn.ballast-data.co.uk/Logo.svg">
<b style="font-size: 4em; line-height: 1; font-weight: 600;"> Fares </b> <br>
</div>
<br>
"""
HTML_CONTENT_FOOTER = """
</div>
<br>
<div style="margin-left: auto; margin-right: auto; width: fit-content; background-color: var(--D1); color: var(--A0); margin-top: 0px; padding: 12px; border-radius: 9px 9px 0 0;">
Open Rail Data Disclaimer Etc. | No Guarantees or Whatever | We do freelance and dont want to be poor.
</div>
</div>
</body>
</html>
"""
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 += "</td> \n </tr>"
text += "</table>"
return HTML_CONTENT_HEADER + text + HTML_CONTENT_FOOTER
with open(template_path, "r") as rf:
return rf.read().replace("<!-- Content -->", text)
def do_GET(self) -> None:
"""