Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 681d50e6b6 | |||
| 19f641a1a6 | |||
| ad2f9b609b |
@@ -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(--C2); color: var(--A0); margin-top: 0px; padding: 12px; border-radius: 0 0 9px 9px; border: 6px solid var(--C1)">
|
||||||
|
<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(--D2); color: var(--A0); margin-top: 0px; padding: 12px; border-radius: 9px 9px 0 0; border: 6px solid var(--D1)">
|
||||||
|
Open Rail Data Disclaimer Etc. | No Guarantees or Whatever | We do freelance and dont want to be poor.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+8
-45
@@ -7,7 +7,7 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|||||||
from logging import INFO, Logger
|
from logging import INFO, Logger
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from pandas.io.formats.style import Styler
|
from pathlib import Path
|
||||||
from requests.exceptions import ConnectionError
|
from requests.exceptions import ConnectionError
|
||||||
|
|
||||||
from fares_site.api_calling import fares_query
|
from fares_site.api_calling import fares_query
|
||||||
@@ -35,45 +35,7 @@ COLUMN_RENAMES = {
|
|||||||
"restriction_code": "Restriction",
|
"restriction_code": "Restriction",
|
||||||
}
|
}
|
||||||
|
|
||||||
HTML_CONTENT_HEADER = """
|
DEFAULT_TEMPLATE_PATH = Path(__file__).parents[2] / "media/template.html"
|
||||||
<!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(--dark-color);">
|
|
||||||
<div style="margin-left: auto; margin-right: auto; width: fit-content; background-color: var(--secondary-accent); 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(--light-color); 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(--secondary-accent);">
|
|
||||||
<br>
|
|
||||||
<img height=80px src="https://cdn.ballast-data.co.uk/Logo.svg">
|
|
||||||
<b style="font-size: 60px; line-height: 1; font-weight: 400;"> RailFares </b> <br>
|
|
||||||
</div>
|
|
||||||
<br>
|
|
||||||
"""
|
|
||||||
|
|
||||||
HTML_CONTENT_FOOTER = """
|
|
||||||
</div>
|
|
||||||
<br>
|
|
||||||
<div style="margin-left: auto; margin-right: auto; width: fit-content; background-color: var(--primary-accent); 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>
|
|
||||||
"""
|
|
||||||
|
|
||||||
logger: Logger = Logger(name=__name__, level=INFO)
|
logger: Logger = Logger(name=__name__, level=INFO)
|
||||||
|
|
||||||
@@ -87,7 +49,7 @@ class FaresHandler(BaseHTTPRequestHandler):
|
|||||||
text = text[1]
|
text = text[1]
|
||||||
return {s.split("=")[0]: s.split("=")[-1] for s in text.split("&")}
|
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.
|
Generates the content of a GET request.
|
||||||
Responsible for receiving the requests' details and constructing the output.
|
Responsible for receiving the requests' details and constructing the output.
|
||||||
@@ -100,7 +62,7 @@ class FaresHandler(BaseHTTPRequestHandler):
|
|||||||
text += (
|
text += (
|
||||||
'<tr style="font-size: 1.6em;"> <th> Flow </th> <th> Fares </th> </tr>\n'
|
'<tr style="font-size: 1.6em;"> <th> Flow </th> <th> Fares </th> </tr>\n'
|
||||||
)
|
)
|
||||||
for flow_fares in data:
|
for flow_fares in sorted(data, key=lambda d: d["flow_id"]["flow_id"]):
|
||||||
flow_table = (
|
flow_table = (
|
||||||
pd.json_normalize(flow_fares["flow_id"])
|
pd.json_normalize(flow_fares["flow_id"])
|
||||||
.rename(COLUMN_RENAMES, axis=1)
|
.rename(COLUMN_RENAMES, axis=1)
|
||||||
@@ -116,13 +78,14 @@ class FaresHandler(BaseHTTPRequestHandler):
|
|||||||
)
|
)
|
||||||
_ = fares_table.hide(axis=0)
|
_ = fares_table.hide(axis=0)
|
||||||
|
|
||||||
text += '<tr> \n <td style="border-top: 6px solid var(--primary-accent); vertical-align: top;">'
|
text += '<tr> \n <td style="border-top: 6px solid var(--D1); vertical-align: top;">'
|
||||||
text += flow_table.to_html()
|
text += flow_table.to_html()
|
||||||
text += '</td> <td style="border-top: 6px solid var(--primary-accent); vertical-align: top;">'
|
text += '</td> <td style="border-top: 6px solid var(--D1); vertical-align: top;">'
|
||||||
text += fares_table.to_html()
|
text += fares_table.to_html()
|
||||||
text += "</td> \n </tr>"
|
text += "</td> \n </tr>"
|
||||||
text += "</table>"
|
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:
|
def do_GET(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user