Catch HTTP errors
This commit is contained in:
		@@ -159,6 +159,7 @@ def print_trip(trip: dict) -> None:
 | 
			
		||||
 | 
			
		||||
def get_next_refresh(data: dict):
 | 
			
		||||
    times = []
 | 
			
		||||
    if data is not None:
 | 
			
		||||
        for trip in data['departureData']:
 | 
			
		||||
            times.append(trip['orgFullTime'])
 | 
			
		||||
            times.append(trip['fullTime'])
 | 
			
		||||
@@ -198,6 +199,7 @@ def _make_status_value_for_sql(trip: dict) -> str:
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def update(station_id: int):
 | 
			
		||||
    try:
 | 
			
		||||
        reply_data = get_data(
 | 
			
		||||
            make_request_data(
 | 
			
		||||
                station_id,
 | 
			
		||||
@@ -205,6 +207,10 @@ def update(station_id: int):
 | 
			
		||||
                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']:
 | 
			
		||||
        print_trip(trip)
 | 
			
		||||
    return reply_data
 | 
			
		||||
@@ -220,6 +226,7 @@ def wait(cxn: mysql.connector.MySQLConnection, station_id: int):
 | 
			
		||||
    cur = cxn.cursor()
 | 
			
		||||
    while True:
 | 
			
		||||
        data = update(station_id)
 | 
			
		||||
        if data is not None:
 | 
			
		||||
            for t in data['departureData']:
 | 
			
		||||
                cur.execute('REPLACE INTO vrr '
 | 
			
		||||
                            '(line_code, direction_code, station_id, orig_datetime, status, delay_value)'
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user