Major tweaks, still no API protection, insecure for live.

This commit is contained in:
2026-06-09 17:16:09 +01:00
parent 681d50e6b6
commit d84f80a998
3 changed files with 58 additions and 15 deletions
+31 -8
View File
@@ -1,5 +1,5 @@
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html style="min-height: 100vh; display: flex;">
<head> <head>
<link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
@@ -16,19 +16,29 @@
.col2 { .col2 {
text-align: left; text-align: left;
} }
input {
font-family: "Merriweather Sans";
font-size: 1em;
border: 3px solid var(--A1);
}
input:hover {
background-color: var(--C2);
}
</style> </style>
</head> </head>
<body style="padding: 0px; margin: 0px;"> <body style="padding: 0px; margin: 0px; min-height: 100%; background-color: var(--A2); display: flex; width: 100%;">
<div style="width: 100%; padding: 0px; margin: 0px; background-color: var(--A0);"> <div style="width: 100%; padding: 0px; margin: 0px; background-color: var(--A0); min-height: 100%; display: flex; flex-direction: column;">
<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)"> <div style="position: sticky; top: 0px; 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> <table>
<tr> <tr>
<td> <td>
<img src="https://cdn.ballast-data.co.uk/Icon-NB.svg"> <a href="/fares">
<img src="https://cdn.ballast-data.co.uk/Icon-NB.svg">
</a>
</td> </td>
<td> <td>
Ballast-Data Product | Ballast-Data Product |
@@ -41,23 +51,36 @@
<br> <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; margin-bottom: 1em; margin-top: 1em; 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);"> <div style="width: fit-content; margin-left: auto; margin-right: auto; border-bottom: 9px solid var(--C1);">
<br> <br>
<img height=80px src="https://cdn.ballast-data.co.uk/Logo.svg"> <a href="/fares">
<img height=80px src="https://cdn.ballast-data.co.uk/Logo.svg">
</a>
<b style="font-size: 4em; line-height: 1; font-weight: 600;"> Fares </b> <br> <b style="font-size: 4em; line-height: 1; font-weight: 600;"> Fares </b> <br>
</div> </div>
<br> <br>
<div style="margin-left: auto; margin-right: auto; width: fit-content;">
<form method="get" action="/fares">
<input name="origin" placeholder="Origin*" style="width: 10em;">
<input name="destination" placeholder="Destination*" style="width: 10em;">
<input name="toc" placeholder="TOC" style="width: 5em;">
<input type="submit" value="Go!" style="width: 5em;">
</form>
</div>
<br>
<!-- Content --> <!-- Content -->
</div> </div>
<br> <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)"> <div style="display: flex; margin-top: auto; margin-left: auto; margin-right: auto; width: fit-content; background-color: var(--D2); color: var(--A0); 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. Open Rail Data Disclaimer Etc. | No Guarantees or Whatever | We do freelance and dont want to be poor.
</div> </div>
</div> </div>
+8 -2
View File
@@ -12,9 +12,15 @@ import json
# Functions # Functions
def fares_query(origin: str, destination: str) -> list[dict[str, dict[str, str]]]: def fares_query(
origin: str,
destination: str,
toc: str | None = None,
) -> list[dict[str, dict[str, str]]]:
url = f"https://fares.ballast-data.co.uk/fares?origin={origin}&destination={destination}"
url += f"&toc={toc}" if toc is not None else ""
response = requests.get( response = requests.get(
url=f"https://fares.ballast-data.co.uk/fares?origin={origin}&destination={destination}", url=url,
auth=( auth=(
environ.get("BD_FARES_USER", ""), environ.get("BD_FARES_USER", ""),
environ.get("BD_FARES_PASS", ""), environ.get("BD_FARES_PASS", ""),
+19 -5
View File
@@ -42,23 +42,37 @@ logger: Logger = Logger(name=__name__, level=INFO)
# Classes # Classes
class FaresHandler(BaseHTTPRequestHandler): class FaresHandler(BaseHTTPRequestHandler):
def parse_url_query(self) -> dict[str, str]: def parse_url_query(self) -> dict[str, str | None]:
text = self.requestline.split(" ")[1].split("?") text = self.requestline.split(" ")[1].split("?")
if len(text) == 1: if len(text) == 1:
return {} return {}
text = text[1] text = text[1]
return {s.split("=")[0]: s.split("=")[-1] for s in text.split("&")} return {
(_s := s.split("="))[0]: _s[-1] if _s[-1] != "" else None
for s in text.split("&")
}
def content_of_GET(self, template_path: Path = DEFAULT_TEMPLATE_PATH) -> 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.
""" """
query_terms = self.parse_url_query()
origin = query_terms.get("origin")
destination = query_terms.get("destination")
if origin is None or destination is None:
text = "Search above including at least Origin and Destination."
with open(template_path, "r") as rf:
return rf.read().replace("<!-- Content -->", text)
assert origin is not None
assert destination is not None
data = fares_query( data = fares_query(
origin=(_d := self.parse_url_query()).get("origin", "NCL"), origin=origin,
destination=_d.get("destination", "NCL"), destination=destination,
toc=query_terms.get("toc"),
) )
text = "<table>" text = '<table style="margin-left: auto; margin-right: auto;">'
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'
) )