Code formatting
Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
parent
87987553e4
commit
c81382e603
2 changed files with 36 additions and 11 deletions
|
@ -81,8 +81,15 @@ class CircuitScraper:
|
|||
|
||||
descriptor_text = states[0].get_text().lower()
|
||||
|
||||
machine.type = MachineType.Dryer if "dryer" in descriptor_text else MachineType.Washer
|
||||
machine.number = descriptor_text.replace("washer", "").replace("dryer", "").strip().upper()
|
||||
machine.type = (
|
||||
MachineType.Dryer if "dryer" in descriptor_text else MachineType.Washer
|
||||
)
|
||||
machine.number = (
|
||||
descriptor_text.replace("washer", "")
|
||||
.replace("dryer", "")
|
||||
.strip()
|
||||
.upper()
|
||||
)
|
||||
|
||||
# Note that CircuitScraper._class_washer is included on every item, hence if it's none of the other ones are
|
||||
# present, we fall back to that one.
|
||||
|
@ -104,7 +111,9 @@ class CircuitScraper:
|
|||
machine.minutes_remaining = None
|
||||
else:
|
||||
minutes_remaining_text = spans[0].get_text(strip=True)
|
||||
machine.minutes_remaining = int(minutes_remaining_text.replace("mins", "").strip())
|
||||
machine.minutes_remaining = int(
|
||||
minutes_remaining_text.replace("mins", "").strip()
|
||||
)
|
||||
else:
|
||||
machine.minutes_remaining = None
|
||||
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import flask
|
||||
|
||||
from circuit_scraper import CircuitScraper, ScraperError
|
||||
|
||||
|
||||
def new() -> flask.Flask:
|
||||
app = flask.Flask(__name__)
|
||||
|
||||
app.add_url_rule("/api/v1/machines/<site_id>", view_func=_api_get_machines, methods=["GET"])
|
||||
app.add_url_rule(
|
||||
"/api/v1/machines/<site_id>", view_func=_api_get_machines, methods=["GET"]
|
||||
)
|
||||
|
||||
return app
|
||||
|
||||
|
@ -14,11 +17,24 @@ def _api_get_machines(site_id: str):
|
|||
try:
|
||||
machines = CircuitScraper.get_site_machine_states(site_id)
|
||||
except ScraperError:
|
||||
return flask.jsonify({"ok": False, "message": "This laundry room is unavailable via CircuitView."}), 400
|
||||
return (
|
||||
flask.jsonify(
|
||||
{
|
||||
"ok": False,
|
||||
"message": "This laundry room is unavailable via CircuitView.",
|
||||
}
|
||||
),
|
||||
400,
|
||||
)
|
||||
|
||||
return flask.jsonify([machine.to_dict() for machine in sorted(
|
||||
machines,
|
||||
# It was annoying me that the machines weren't sorted by number. This sorts the machines by number, taking into
|
||||
# account the fact that some machine numbers include letters, which are quietly ignored.
|
||||
key=lambda x: int("".join(filter(lambda y: y.isdigit(), x.number)))
|
||||
)])
|
||||
return flask.jsonify(
|
||||
[
|
||||
machine.to_dict()
|
||||
for machine in sorted(
|
||||
machines,
|
||||
# It was annoying me that the machines weren't sorted by number. This sorts the machines by number, taking into
|
||||
# account the fact that some machine numbers include letters, which are quietly ignored.
|
||||
key=lambda x: int("".join(filter(lambda y: y.isdigit(), x.number))),
|
||||
)
|
||||
]
|
||||
)
|
||||
|
|
Reference in a new issue