Browse Source

Fixed handling of stations with only arr/dep

python3
Dan Cojocaru 3 years ago
parent
commit
5ab092eed5
Signed by: kbruen
GPG Key ID: 818A889458EDC937
  1. 3
      scraper/scrape_station.py
  2. 4
      scraper/scrape_station_schema_v2.json
  3. 10
      server/server/db.py

3
scraper/scrape_station.py

@ -46,6 +46,9 @@ def scrape(station_name: str):
tz = pytz.timezone('Europe/Bucharest') tz = pytz.timezone('Europe/Bucharest')
def parse_arrdep_list(elem, end_station_field_name): def parse_arrdep_list(elem, end_station_field_name):
if elem.div.ul is None:
return None
def parse_item(elem): def parse_item(elem):
result = {} result = {}

4
scraper/scrape_station_schema_v2.json

@ -71,7 +71,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"arrivals": { "arrivals": {
"type": "array", "type": ["array", "null"],
"items": { "items": {
"allOf": [ "allOf": [
{ {
@ -96,7 +96,7 @@
} }
}, },
"departures": { "departures": {
"type": "array", "type": ["array", "null"],
"items": { "items": {
"allOf": [ "allOf": [
{ {

10
server/server/db.py

@ -165,7 +165,9 @@ def on_station(station_data: dict):
found_train_at_station(station, train_number) found_train_at_station(station, train_number)
with db_transaction(): with db_transaction():
for train in station_data['arrivals']: if station_data['arrivals']:
process_train(train) for train in station_data['arrivals']:
for train in station_data['departures']: process_train(train)
process_train(train) if station_data['departures']:
for train in station_data['departures']:
process_train(train)

Loading…
Cancel
Save