async def api_crime(request):
    """
    Gets the crime nearby to a given postcode.
    :param request: The aiohttp request.
    :return: A json representation of the crimes near the postcode.
    """
    postcode: Optional[str] = request.match_info.get('postcode', None)

    try:
        coroutine = get_postcode_random() if postcode == "random" else get_postcode(postcode)
        postcode: Optional[Postcode] = await coroutine
    except CachingError as e:
        return web.Response(body=e.status, status=500)

    try:
        crime = await fetch_crime(postcode.lat, postcode.long)
    except (ApiError, CircuitBreakerError):
        raise web.HTTPInternalServerError(body=f"Requested crime is not cached, and can't be retrieved.")

    if crime is None:
        return web.HTTPNotFound(body="No Police Data")
    else:
        return str_json_response(crime)
async def api_crime(request):
    """
    Gets the crime nearby to a given postcode.
    :param request: The aiohttp request.
    :return: A json representation of the crimes near the postcode.
    """
    postcode: Optional[str] = request.match_info.get('postcode', None)

    try:
        coroutine = get_postcode_random() if postcode == "random" else get_postcode(postcode)
        postcode: Optional[Postcode] = await coroutine
    except CachingError as e:
        return web.Response(body=e.status, status=500)

    try:
        crime = await fetch_crime(postcode.lat, postcode.long)
    except (ApiError, CircuitBreakerError):
        raise web.HTTPInternalServerError(body=f"Requested crime is not cached, and can't be retrieved.")

    if crime is None:
        return web.HTTPNotFound(body="No Police Data")
    else:
        return str_json_response(crime)
async def api_crime ( request ) : postcode : Optional [ str ] = request . match_info . get ( 'postcode' , None ) try : coroutine = get_postcode_random ( ) if postcode == "random" else get_postcode ( postcode ) postcode : Optional [ Postcode ] = await coroutine except CachingError as e : return web . Response ( body = e . status , status = 500 ) try : crime = await fetch_crime ( postcode . lat , postcode . long ) except ( ApiError , CircuitBreakerError ) : raise web . HTTPInternalServerError ( body = f"Requested crime is not cached, and can't be retrieved." ) if crime is None : return web . HTTPNotFound ( body = "No Police Data" ) else : return str_json_response ( crime )
Gets the crime nearby to a given postcode.
    :param request: The aiohttp request.
    :return: A json representation of the crimes near the postcode.
Gets the crime nearby to a given postcode . : param request : The aiohttp request . : return : A json representation of the crimes near the postcode .