diff --git a/scraper/scrape_station.py b/scraper/scrape_station.py index 4b08272..fc9cc93 100644 --- a/scraper/scrape_station.py +++ b/scraper/scrape_station.py @@ -46,6 +46,9 @@ def scrape(station_name: str): tz = pytz.timezone('Europe/Bucharest') def parse_arrdep_list(elem, end_station_field_name): + if elem.div.ul is None: + return None + def parse_item(elem): result = {} diff --git a/scraper/scrape_station_schema_v2.json b/scraper/scrape_station_schema_v2.json index 6233c1c..a6b18f5 100644 --- a/scraper/scrape_station_schema_v2.json +++ b/scraper/scrape_station_schema_v2.json @@ -71,7 +71,7 @@ "type": "object", "properties": { "arrivals": { - "type": "array", + "type": ["array", "null"], "items": { "allOf": [ { @@ -96,7 +96,7 @@ } }, "departures": { - "type": "array", + "type": ["array", "null"], "items": { "allOf": [ { diff --git a/server/server/db.py b/server/server/db.py index 05ec249..3136c21 100644 --- a/server/server/db.py +++ b/server/server/db.py @@ -165,7 +165,9 @@ def on_station(station_data: dict): found_train_at_station(station, train_number) with db_transaction(): - for train in station_data['arrivals']: - process_train(train) - for train in station_data['departures']: - process_train(train) + if station_data['arrivals']: + for train in station_data['arrivals']: + process_train(train) + if station_data['departures']: + for train in station_data['departures']: + process_train(train)