Major tweaks, still no API protection, insecure for live.
This commit is contained in:
+29
-6
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<html style="min-height: 100vh; display: flex;">
|
||||
<head>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
@@ -16,19 +16,29 @@
|
||||
.col2 {
|
||||
text-align: left;
|
||||
}
|
||||
input {
|
||||
font-family: "Merriweather Sans";
|
||||
font-size: 1em;
|
||||
border: 3px solid var(--A1);
|
||||
}
|
||||
input:hover {
|
||||
background-color: var(--C2);
|
||||
}
|
||||
</style>
|
||||
|
||||
</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>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="/fares">
|
||||
<img src="https://cdn.ballast-data.co.uk/Icon-NB.svg">
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
Ballast-Data Product |
|
||||
@@ -41,23 +51,36 @@
|
||||
|
||||
<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);">
|
||||
<br>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<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 -->
|
||||
|
||||
</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)">
|
||||
<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.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -12,9 +12,15 @@ import json
|
||||
|
||||
|
||||
# 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(
|
||||
url=f"https://fares.ballast-data.co.uk/fares?origin={origin}&destination={destination}",
|
||||
url=url,
|
||||
auth=(
|
||||
environ.get("BD_FARES_USER", ""),
|
||||
environ.get("BD_FARES_PASS", ""),
|
||||
|
||||
+19
-5
@@ -42,23 +42,37 @@ logger: Logger = Logger(name=__name__, level=INFO)
|
||||
|
||||
# Classes
|
||||
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("?")
|
||||
if len(text) == 1:
|
||||
return {}
|
||||
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:
|
||||
"""
|
||||
Generates the content of a GET request.
|
||||
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(
|
||||
origin=(_d := self.parse_url_query()).get("origin", "NCL"),
|
||||
destination=_d.get("destination", "NCL"),
|
||||
origin=origin,
|
||||
destination=destination,
|
||||
toc=query_terms.get("toc"),
|
||||
)
|
||||
text = "<table>"
|
||||
text = '<table style="margin-left: auto; margin-right: auto;">'
|
||||
text += (
|
||||
'<tr style="font-size: 1.6em;"> <th> Flow </th> <th> Fares </th> </tr>\n'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user