Add exception catch

This commit is contained in:
Fred Boniface 2024-10-03 12:40:15 +01:00
parent 69ec6d2732
commit 7585453ff0

View File

@ -39,14 +39,18 @@ def get_services(headcode, date):
results = [] results = []
url = OB_TRN_BASE_URL + f"{date.strftime('%Y-%m-%d')}/headcode/{headcode.lower()}" url = OB_TRN_BASE_URL + f"{date.strftime('%Y-%m-%d')}/headcode/{headcode.lower()}"
print(url) print(url)
res = requests.get(url, headers=HEADERS) try:
if res.status_code == 200: res = requests.get(url, headers=HEADERS)
json_res = res.json() if res.status_code == 200:
for item in json_res: json_res = res.json()
if item['operator'] == 'GW': for item in json_res:
results.append(item) if item['operator'] == 'GW':
print(f"Found {len(results)} valid GWR Service") results.append(item)
return results print(f"Found {len(results)} valid GWR Service")
return results
except Exception as e:
print(e)
sys.exit()
def get_service_detail(trainUid, date): def get_service_detail(trainUid, date):
try: try: