Catch HTTP errors

This commit is contained in:
Christopher Teutsch 2019-05-16 16:36:29 +02:00
parent 0fa0126dbc
commit f05d639fe5
Signed by: iwonder
GPG Key ID: 0EE33D788D50130D

View File

@ -159,6 +159,7 @@ def print_trip(trip: dict) -> None:
def get_next_refresh(data: dict): def get_next_refresh(data: dict):
times = [] times = []
if data is not None:
for trip in data['departureData']: for trip in data['departureData']:
times.append(trip['orgFullTime']) times.append(trip['orgFullTime'])
times.append(trip['fullTime']) times.append(trip['fullTime'])
@ -198,6 +199,7 @@ def _make_status_value_for_sql(trip: dict) -> str:
def update(station_id: int): def update(station_id: int):
try:
reply_data = get_data( reply_data = get_data(
make_request_data( make_request_data(
station_id, station_id,
@ -205,6 +207,10 @@ def update(station_id: int):
lines=lines_filter lines=lines_filter
) )
) )
except requests.exceptions.HTTPError as e:
print("Could not get the data: " + str(e))
return None
for trip in reply_data['departureData']: for trip in reply_data['departureData']:
print_trip(trip) print_trip(trip)
return reply_data return reply_data
@ -220,6 +226,7 @@ def wait(cxn: mysql.connector.MySQLConnection, station_id: int):
cur = cxn.cursor() cur = cxn.cursor()
while True: while True:
data = update(station_id) data = update(station_id)
if data is not None:
for t in data['departureData']: for t in data['departureData']:
cur.execute('REPLACE INTO vrr ' cur.execute('REPLACE INTO vrr '
'(line_code, direction_code, station_id, orig_datetime, status, delay_value)' '(line_code, direction_code, station_id, orig_datetime, status, delay_value)'