예제 #1
0
def search_for_address(query, api_key=None, fields=["formatted_address"]):
    """Search for the address of a given name."""
    if api_key is None:
        api_key = get_google_maps_api_key()
    gmaps = Client(key=api_key)
    place = places.find_place(gmaps, query, "textquery", fields=fields)
    return place["candidates"]
예제 #2
0
def get_place_details(
    query: str,
    api_key: Optional[str] = None,
    fields: Optional[List[str]] = None,
):
    """Get the place details for a given a name.
    Args:
        query (str): The text to use to search for a place.
        api_key (str): Optional Google Maps API key, None by default.
        fields (list): Optional fields to retrieve.
    Returns:
        (dict): A dictionary of place details.
    """
    if api_key is None:
        api_key = get_google_maps_api_key()
    if not fields:
        fields = [
            'formatted_address',
            'photo',
            'opening_hours',
            'website',
        ]
    gmaps = Client(key=api_key)
    search = places.find_place(gmaps, query, 'textquery')
    place_id = search['candidates'][0]['place_id']
    place = places.place(gmaps, place_id, fields=fields)
    return place['result']
 def search_for_places(self, query, location_bias="ipbias"):
     return places.find_place(
         client=self._client,
         fields=self._fields,
         input=query,
         input_type=TEXT_QUERY,
         location_bias=location_bias,
     )
예제 #4
0
def get_place_details(query, api_key=None, fields=[]):
    """Get the place details for a given a name."""
    if api_key is None:
        api_key = get_google_maps_api_key()
    if not fields:
        fields = [
            "formatted_address",
            "photo",
            "opening_hours",
            "website",
        ]
    gmaps = Client(key=api_key)
    search = places.find_place(gmaps, query, "textquery")
    place_id = search["candidates"][0]["place_id"]
    place = places.place(gmaps, place_id, fields=fields)
    return place["result"]
예제 #5
0
def map_district_to_deaths(deaths):
    gmaps = googlemaps.Client(key=os.getenv("GOOGLE_PLACES_API_KEY"))
    districts_deaths_per_day = {}
    for hospital in deaths.keys():
        places = find_place(gmaps, [hospital],
                            "textquery",
                            fields=["place_id"])
        if len(places["candidates"]) == 0:
            print(
                f"Warning could not find address for {hospital}. Skipping...")
            continue
        place_details = place(gmaps, places["candidates"][0]['place_id'])
        district = next(
            iter([
                p["long_name"]
                for p in place_details["result"]["address_components"]
                if "administrative_area_level_2" in p["types"]
            ]))
        if len(places) > 1:
            print(
                f"Using {district} more than one address for {hospital}, using data {', '.join([p['short_name'] for p in place_details['result']['address_components']])}"
            )
        if district in districts_deaths_per_day:
            districts_deaths_per_day[district] = {
                date: {
                    "deathsDaily":
                    districts_deaths_per_day[district][date]["deathsDaily"]
                    or 0 + deaths[hospital][date]
                } or 0
                for date in deaths[hospital].keys()
            }
        else:
            districts_deaths_per_day[district] = {
                date: {
                    "deathsDaily": deaths[hospital][date]
                }
                for date in deaths[hospital].keys()
            }
    calculate_death_totals(districts_deaths_per_day)

    if "City of Bristol" in districts_deaths_per_day:
        districts_deaths_per_day[
            "Bristol, City of"] = districts_deaths_per_day["City of Bristol"]
        del districts_deaths_per_day["City of Bristol"]
    return districts_deaths_per_day
예제 #6
0
def search_for_address(
    query: str,
    api_key: Optional[str] = None,
    fields: Optional[List[str]] = None,
) -> List[dict]:
    """Search for the address of a given name.
    Args:
        query (str): The text to use to search for an address.
        api_key (): Optional, None by default.
        fields (list): Optional, `formatted_address` is included by default.
    Returns:
        (list): A list of potential results.
    """
    if api_key is None:
        api_key = get_google_maps_api_key()
    if fields is None:
        fields = ['formatted_address']
    gmaps = Client(key=api_key)
    place = places.find_place(gmaps, query, 'textquery', fields=fields)
    return place['candidates']