From 44fca21cc8f34484a63bdecab0bca5dc580643ef Mon Sep 17 00:00:00 2001 From: 2mal3 <56305732+2mal3@users.noreply.github.com> Date: Sat, 13 Jan 2024 16:00:05 +0100 Subject: [PATCH] style: black --- verspaetungsorakel/bahn.py | 10 ++++++---- verspaetungsorakel/database.py | 4 ++-- verspaetungsorakel/main.py | 14 ++++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/verspaetungsorakel/bahn.py b/verspaetungsorakel/bahn.py index bde749f..23ceb30 100644 --- a/verspaetungsorakel/bahn.py +++ b/verspaetungsorakel/bahn.py @@ -1,12 +1,13 @@ +from datetime import date, datetime +from os import getenv + from deutsche_bahn_api.api_authentication import ApiAuthentication from deutsche_bahn_api.station_helper import StationHelper from deutsche_bahn_api.timetable_helper import TimetableHelper from deutsche_bahn_api.train import Train from deutsche_bahn_api.train_changes import TrainChanges -from os import getenv -from datetime import date, datetime from dotenv import load_dotenv -from pony.orm import db_session, delete, ObjectNotFound +from pony.orm import db_session from verspaetungsorakel.database import Stop, Train, Trip, Station @@ -111,7 +112,8 @@ def get_delays(): if db_stop.arrival and new_arrival: db_stop.arrival_delay = int(round((new_arrival - db_stop.arrival).total_seconds() / 60, 0)) if db_stop.departure and new_departure: - db_stop.departure_delay = int(round((new_departure - db_stop.departure).total_seconds() / 60, 0)) + db_stop.departure_delay = int( + round((new_departure - db_stop.departure).total_seconds() / 60, 0)) if __name__ == "__main__": diff --git a/verspaetungsorakel/database.py b/verspaetungsorakel/database.py index 143d434..6191a99 100644 --- a/verspaetungsorakel/database.py +++ b/verspaetungsorakel/database.py @@ -1,8 +1,8 @@ import sqlite3 from datetime import date, datetime -from pony.orm import * from pathlib import Path -import os + +from pony.orm import * Path("database").mkdir(parents=True, exist_ok=True) diff --git a/verspaetungsorakel/main.py b/verspaetungsorakel/main.py index b0691d2..6be2a01 100644 --- a/verspaetungsorakel/main.py +++ b/verspaetungsorakel/main.py @@ -1,16 +1,17 @@ +from contextlib import asynccontextmanager +from datetime import date, timedelta + +from apscheduler.schedulers.asyncio import AsyncIOScheduler from fastapi import FastAPI, Request, HTTPException from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates from pony.orm import db_session, select, desc -from apscheduler.schedulers.asyncio import AsyncIOScheduler from slowapi import Limiter, _rate_limit_exceeded_handler -from slowapi.util import get_remote_address from slowapi.errors import RateLimitExceeded -from datetime import date, timedelta -from contextlib import asynccontextmanager +from slowapi.util import get_remote_address -from verspaetungsorakel.database import Station, Train, Stop from verspaetungsorakel.bahn import write_timetables_to_database, get_delays, write_stations_to_database +from verspaetungsorakel.database import Station, Train, Stop VERSION = "0.2.8" @@ -63,7 +64,8 @@ def index(request: Request, station: str = None, train: str = None): if not db_station: raise HTTPException(status_code=404, detail="Station not found") - db_stop = Stop.select(lambda s: s.station == db_station and s.trip.train == db_train).order_by(lambda s: desc(s.trip.date)).first() + db_stop = Stop.select(lambda s: s.station == db_station and s.trip.train == db_train).order_by( + lambda s: desc(s.trip.date)).first() if not db_stop: return templates.TemplateResponse("index.html", { "request": request,