Skip to content

Commit

Permalink
feat: add new place details fields and reviews request modifiers (#474)
Browse files Browse the repository at this point in the history
* feat: add new place details fields and support for reviews sorting and translation

* feat: support reviews (plural) field
  • Loading branch information
wangela authored Jan 26, 2023
1 parent 72c482c commit 6c69310
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 36 deletions.
97 changes: 66 additions & 31 deletions googlemaps/places.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,43 +52,72 @@
^ PLACES_FIND_FIELDS_ATMOSPHERE
)

PLACES_DETAIL_FIELDS_BASIC = {"address_component",
"adr_address",
"business_status",
"formatted_address",
"geometry",
"geometry/location",
"geometry/location/lat",
"geometry/location/lng",
"geometry/viewport",
"geometry/viewport/northeast",
"geometry/viewport/northeast/lat",
"geometry/viewport/northeast/lng",
"geometry/viewport/southwest",
"geometry/viewport/southwest/lat",
"geometry/viewport/southwest/lng",
"icon",
"name",
"permanently_closed",
"photo",
"place_id",
"plus_code",
"type",
"url",
"utc_offset",
"vicinity",}

PLACES_DETAIL_FIELDS_CONTACT = {"formatted_phone_number", "international_phone_number", "opening_hours", "website"}

PLACES_DETAIL_FIELDS_ATMOSPHERE = {"editorial_summary","price_level", "rating", "review", "user_ratings_total"}
PLACES_DETAIL_FIELDS_BASIC = {
"address_component",
"adr_address",
"business_status",
"formatted_address",
"geometry",
"geometry/location",
"geometry/location/lat",
"geometry/location/lng",
"geometry/viewport",
"geometry/viewport/northeast",
"geometry/viewport/northeast/lat",
"geometry/viewport/northeast/lng",
"geometry/viewport/southwest",
"geometry/viewport/southwest/lat",
"geometry/viewport/southwest/lng",
"icon",
"name",
"permanently_closed",
"photo",
"place_id",
"plus_code",
"type",
"url",
"utc_offset",
"vicinity",
"wheelchair_accessible_entrance"
}

PLACES_DETAIL_FIELDS_CONTACT = {
"formatted_phone_number",
"international_phone_number",
"opening_hours",
"current_opening_hours",
"secondary_opening_hours",
"website",
}

PLACES_DETAIL_FIELDS_ATMOSPHERE = {
"curbside_pickup",
"delivery",
"dine_in",
"editorial_summary",
"price_level",
"rating",
"reservable",
"review", # prefer "reviews" to match API documentation
"reviews",
"serves_beer",
"serves_breakfast",
"serves_brunch",
"serves_dinner",
"serves_lunch",
"serves_vegetarian_food",
"serves_wine",
"takeout",
"user_ratings_total"
}

PLACES_DETAIL_FIELDS = (
PLACES_DETAIL_FIELDS_BASIC
^ PLACES_DETAIL_FIELDS_CONTACT
^ PLACES_DETAIL_FIELDS_ATMOSPHERE
)

DEPRECATED_FIELDS = {"permanently_closed"}
DEPRECATED_FIELDS = {"permanently_closed", "review"}
DEPRECATED_FIELDS_MESSAGE = (
"Fields, %s, are deprecated. "
"Read more at https://developers.google.com/maps/deprecations."
Expand Down Expand Up @@ -402,7 +431,8 @@ def place(
session_token=None,
fields=None,
language=None,
reviews_sort="most_relevant"
reviews_no_translations=False,
reviews_sort="most_relevant",
):
"""
Comprehensive details for an individual place.
Expand All @@ -423,6 +453,9 @@ def place(
:param language: The language in which to return results.
:type language: string
:param reviews_no_translations: Specify reviews_no_translations=True to disable translation of reviews; reviews_no_translations=False (default) enables translation of reviews.
:type reviews_no_translations: bool
:param reviews_sort: The sorting method to use when returning reviews.
Can be set to most_relevant (default) or newest.
:type reviews_sort: string
Expand Down Expand Up @@ -455,6 +488,8 @@ def place(
params["language"] = language
if session_token:
params["sessiontoken"] = session_token
if reviews_no_translations:
params["reviews_no_translations"] = "true"
if reviews_sort:
params["reviews_sort"] = reviews_sort

Expand Down
12 changes: 7 additions & 5 deletions tests/test_places.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def setUp(self):
self.type = "liquor_store"
self.language = "en-AU"
self.region = "AU"
self.reviews_sort="newest"
self.radius = 100

@responses.activate
Expand Down Expand Up @@ -164,15 +163,18 @@ def test_place_detail(self):

self.client.place(
"ChIJN1t_tDeuEmsRUsoyG83frY4",
fields=["business_status", "geometry/location", "place_id"],
fields=["business_status", "geometry/location",
"place_id", "reviews"],
language=self.language,
reviews_sort=self.reviews_sort,
reviews_no_translations=True,
reviews_sort="newest",
)

self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"%s?reviews_sort=newest&language=en-AU&placeid=ChIJN1t_tDeuEmsRUsoyG83frY4"
"&key=%s&fields=business_status,geometry/location,place_id"
"%s?language=en-AU&placeid=ChIJN1t_tDeuEmsRUsoyG83frY4"
"&reviews_no_translations=true&reviews_sort=newest"
"&key=%s&fields=business_status,geometry/location,place_id,reviews"
% (url, self.key),
responses.calls[0].request.url,
)
Expand Down

0 comments on commit 6c69310

Please sign in to comment.