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,6 +39,7 @@ 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)
try:
res = requests.get(url, headers=HEADERS) res = requests.get(url, headers=HEADERS)
if res.status_code == 200: if res.status_code == 200:
json_res = res.json() json_res = res.json()
@ -47,6 +48,9 @@ def get_services(headcode, date):
results.append(item) results.append(item)
print(f"Found {len(results)} valid GWR Service") print(f"Found {len(results)} valid GWR Service")
return results return results
except Exception as e:
print(e)
sys.exit()
def get_service_detail(trainUid, date): def get_service_detail(trainUid, date):
try: try: