Return response.json() from client functions

This commit is contained in:
Fred Boniface 2024-10-31 17:04:28 +00:00
parent 8dbb24f19c
commit d92256f051

View File

@ -70,14 +70,14 @@ class OwlBoardClient:
logger.debug(f"Generated URL: {url_path}")
response = self._make_request('GET', url_path)
logger.info("Response received for get_stops_by_pis")
print(response.text)
return response.json()
def get_pis_by_start_end_crs(self, start_crs: str, end_crs: str):
url_path = url_multijoin(self.base_url, ENDPOINTS['PIS_BY_START_END_CRS'], start_crs, end_crs)
logger.debug(f"Generated URL: {url_path}")
response = self._make_request('GET', url_path)
logger.info("Response received for get_pis_by_start_end_crs")
print(response.text)
return response.json()
def get_pis_by_tiploc_list(self, tiplocs: List[str]):
return
@ -106,7 +106,7 @@ class OwlBoardClient:
# Send request
response = self._make_request('GET', url_path)
logger.info("Response received for get_trains_by_headcode")
print(response.text)
return response.json()
def get_trains_by_trainUid(self, train_uid: str, date: datetime):
if not isinstance(train_uid, str):
@ -131,7 +131,7 @@ class OwlBoardClient:
# Send request
response = self._make_request('GET', url_path)
logger.info("Response received for get_trains_by_trainUid")
print(response.text)
return response.json()
## Location Reference Methods ##
@ -142,13 +142,25 @@ class OwlBoardClient:
# Send Request
response = self._make_request('GET', url_path)
logger.info("Response received for get_trains_by_trainUid")
print(response.text)
return response.json()
## Location Reference Methods ##
def get_loc_ref_codes_by_tiploc(self, tiploc: str):
url_path = url_multijoin(self.base_url, ENDPOINTS['REF_LOCATION_BY_TIPLOC'], tiploc)
logger.debug(f"Generated URL: {url_path}")
# Send Request
response = self._make_request('GET', url_path)
logger.info("Response received for get_trains_by_trainUid")
return response.json()
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
try:
client = OwlBoardClient(base_url='https://owlboard.info', api_key="x")
client.get_loc_ref_codes_by_tiploc('BATHSPA')
test = client.get_trains_by_headcode("1A99", datetime.now())
print(test)
except Exception as e:
logger.error(f"Failed to create client: {e}")