hyperion/fetch/police.py
async def fetch_neighbourhood(lat: float, long: float) -> Optional[dict]:
    """
    Gets the neighbourhood from the fetch that is associated with the given postcode.
    :return: A neighbourhood object parsed from the fetch.
    :raise ApiError: When there was an error connecting to the API.
    """

    lookup_url = f"https://data.police.uk/api/locate-neighbourhood?q={lat},{long}"

    async with ClientSession() as session:
        try:
            async with session.get(lookup_url) as request:
                if request.status == 404:
                    return None
                neighbourhood = await request.json()
        except ClientConnectionError as con_err:
            logger.debug(f"Could not connect to {con_err.host}")
            raise ApiError(f"Could not connect to {con_err.host}")
        except JSONDecodeError as dec_err:
            logger.error(f"Could not decode data: {dec_err}")
            raise ApiError(f"Could not decode data: {dec_err}")

        neighbourhood_url = f"https://data.police.uk/api/{neighbourhood['force']}/{neighbourhood['neighbourhood']}"

        try:
            async with session.get(neighbourhood_url) as request:
                neighbourhood_data = await request.json()
        except ConnectionError as con_err:
            logger.debug(f"Could not connect to {con_err.args[0].pool.host}")
            raise ApiError(f"Could not connect to {con_err.args[0].pool.host}")
        except JSONDecodeError as dec_err:
            logger.error(f"Could not decode data: {dec_err}")
            raise ApiError(f"Could not decode data: {dec_err}")

        return neighbourhood_data
async def fetch_neighbourhood(lat: float, long: float) -> Optional[dict]:
    """
    Gets the neighbourhood from the fetch that is associated with the given postcode.
    :return: A neighbourhood object parsed from the fetch.
    :raise ApiError: When there was an error connecting to the API.
    """

    lookup_url = f"https://data.police.uk/api/locate-neighbourhood?q={lat},{long}"

    async with ClientSession() as session:
        try:
            async with session.get(lookup_url) as request:
                if request.status == 404:
                    return None
                neighbourhood = await request.json()
        except ClientConnectionError as con_err:
            logger.debug(f"Could not connect to {con_err.host}")
            raise ApiError(f"Could not connect to {con_err.host}")
        except JSONDecodeError as dec_err:
            logger.error(f"Could not decode data: {dec_err}")
            raise ApiError(f"Could not decode data: {dec_err}")

        neighbourhood_url = f"https://data.police.uk/api/{neighbourhood['force']}/{neighbourhood['neighbourhood']}"

        try:
            async with session.get(neighbourhood_url) as request:
                neighbourhood_data = await request.json()
        except ConnectionError as con_err:
            logger.debug(f"Could not connect to {con_err.args[0].pool.host}")
            raise ApiError(f"Could not connect to {con_err.args[0].pool.host}")
        except JSONDecodeError as dec_err:
            logger.error(f"Could not decode data: {dec_err}")
            raise ApiError(f"Could not decode data: {dec_err}")

        return neighbourhood_data
async def fetch_neighbourhood ( lat : float , long : float ) -> Optional [ dict ] : lookup_url = f"https://data.police.uk/api/locate-neighbourhood?q={lat},{long}" async with ClientSession ( ) as session : try : async with session . get ( lookup_url ) as request : if request . status == 404 : return None neighbourhood = await request . json ( ) except ClientConnectionError as con_err : logger . debug ( f"Could not connect to {con_err.host}" ) raise ApiError ( f"Could not connect to {con_err.host}" ) except JSONDecodeError as dec_err : logger . error ( f"Could not decode data: {dec_err}" ) raise ApiError ( f"Could not decode data: {dec_err}" ) neighbourhood_url = f"https://data.police.uk/api/{neighbourhood['force']}/{neighbourhood['neighbourhood']}" try : async with session . get ( neighbourhood_url ) as request : neighbourhood_data = await request . json ( ) except ConnectionError as con_err : logger . debug ( f"Could not connect to {con_err.args[0].pool.host}" ) raise ApiError ( f"Could not connect to {con_err.args[0].pool.host}" ) except JSONDecodeError as dec_err : logger . error ( f"Could not decode data: {dec_err}" ) raise ApiError ( f"Could not decode data: {dec_err}" ) return neighbourhood_data
Gets the neighbourhood from the fetch that is associated with the given postcode.
    :return: A neighbourhood object parsed from the fetch.
    :raise ApiError: When there was an error connecting to the API.
Gets the neighbourhood from the fetch that is associated with the given postcode . : return : A neighbourhood object parsed from the fetch . : raise ApiError : When there was an error connecting to the API .