class GOPprovider(basicProvider, goLocation): """ This class is used to: 1. Make the connection to the Google Places API 2. Get user's Photos 3. Get OPENi album Photos 4. Post Photos to OPENi album """ def __init__(self): """ Initiate the connector """ YOUR_API_KEY = "AIzaSyDoZ455JKv5GS2DgmK1jQc7R8Oj5JVjEnI" self.connector = GooglePlaces(YOUR_API_KEY) def get_nearby_places(self, data): """ EXTRA!!! Find nearby places """ raw_datas = self.connector.nearby_search( location="London, England", keyword="Fish and Chips", radius=20000, types=[types.TYPE_FOOD] ) fields = [ "id", "type", "service", "url", "user.id", "user.username", "website", "name", "details.formatted_address", "details.formatted_address.number", "geo_location.lat", "geo_location.lng", "created_time", "types", ] alternatives = ["", "place", "openi", "", "", "", "", "", "", "", "", "", "", ""] response = {"meta": {"total_count": "blah", "next": "bla"}, "data": []} for raw_data in raw_datas.places: data = self.get_fields(raw_data, fields, alternatives) response["data"].append(self.format_place_response(data)) return response def add_a_place(self, data): """ EXTRA!!! Add a new place """ # Returns a detailed instance of googleplaces.Place raw_data = self.connector.add_place( name=data["name"], lat_lng={"lat": data["lat"], "lng": data["lng"]}, accuracy=data["accuracy"], types=data["type"], language=data["lang"], ) response = {"added_place_reference": raw_data.reference, "added_place_id": raw_data.id} return response def delete_a_place(self, data): """ DELETE API_PATH/[PLACE_ID] """ # Returns a detailed instance of googleplaces.Place raw_data = self.connector.delete_place(data["reference"]) return {"status": "OK"}
class GOPprovider(basicProvider, goActivity, goLocation, goMedia, goProductsServices, goProfiles): ''' This class is used to: 1. Make the connection to the Google Places API 2. Get user's Photos 3. Get OPENi album Photos 4. Post Photos to OPENi album ''' def __init__(self): ''' Initiate the connector ''' YOUR_API_KEY = 'AIzaSyDoZ455JKv5GS2DgmK1jQc7R8Oj5JVjEnI' self.connector = GooglePlaces(YOUR_API_KEY) def get_nearby_places(self, data): """ EXTRA!!! Find nearby places """ raw_datas = self.connector.nearby_search(location='London, England', keyword='Fish and Chips', radius=20000, types=[types.TYPE_FOOD]) fields = [ 'id', 'type', 'service', 'url', 'user.id', 'user.username', 'website', 'name', 'details.formatted_address', 'details.formatted_address.number', 'geo_location.lat', 'geo_location.lng', 'created_time', 'types' ] alternatives = [ '', 'place', 'openi', '', '', '', '', '', '', '', '', '', '', '' ] response = {'meta': {'total_count': 'blah', 'next': 'bla'}, 'data': []} for raw_data in raw_datas.places: data = self.get_fields(raw_data, fields, alternatives) response['data'].append(self.format_place_response(data)) return response def add_a_place(self, data): """ EXTRA!!! Add a new place """ # Returns a detailed instance of googleplaces.Place raw_data = self.connector.add_place(name=data['name'], lat_lng={ 'lat': data['lat'], 'lng': data['lng'] }, accuracy=data['accuracy'], types=data['type'], language=data['lang']) response = { 'added_place_reference': raw_data.reference, 'added_place_id': raw_data.id } return response def delete_a_place(self, data): """ DELETE API_PATH/[PLACE_ID] """ # Returns a detailed instance of googleplaces.Place raw_data = self.connector.delete_place(data['reference']) return {'status': 'OK'}
class GOPprovider(basicProvider, goActivity, goLocation, goMedia, goProductsServices, goProfiles): ''' This class is used to: 1. Make the connection to the Google Places API 2. Get user's Photos 3. Get OPENi album Photos 4. Post Photos to OPENi album ''' def __init__(self): ''' Initiate the connector ''' YOUR_API_KEY = 'AIzaSyDoZ455JKv5GS2DgmK1jQc7R8Oj5JVjEnI' self.connector = GooglePlaces(YOUR_API_KEY) def get_nearby_places(self, data): """ EXTRA!!! Find nearby places """ raw_datas = self.connector.nearby_search(location='London, England', keyword='Fish and Chips', radius=20000, types=[types.TYPE_FOOD]) fields = ['id', 'type', 'service', 'url', 'user.id', 'user.username', 'website', 'name', 'details.formatted_address', 'details.formatted_address.number', 'geo_location.lat', 'geo_location.lng', 'created_time', 'types'] alternatives = ['', 'place', 'openi', '', '', '', '', '', '', '', '', '', '', ''] response = { 'meta': { 'total_count': 'blah', 'next': 'bla' }, 'data': [] } for raw_data in raw_datas.places: data = self.get_fields(raw_data, fields, alternatives) response['data'].append(self.format_place_response(data)) return response def add_a_place(self, data): """ EXTRA!!! Add a new place """ # Returns a detailed instance of googleplaces.Place raw_data = self.connector.add_place(name=data['name'], lat_lng={'lat': data['lat'], 'lng': data['lng']}, accuracy=data['accuracy'], types=data['type'], language=data['lang']) response = { 'added_place_reference': raw_data.reference, 'added_place_id': raw_data.id } return response def delete_a_place(self, data): """ DELETE API_PATH/[PLACE_ID] """ # Returns a detailed instance of googleplaces.Place raw_data = self.connector.delete_place(data['reference']) return { 'status': 'OK' }
# Image URL photo.url # Original filename (optional) photo.filename # Raw image data photo.data # Are there any additional pages of results? if query_result.has_next_page_token: query_result_next_page = google_places.nearby_search( pagetoken=query_result.next_page_token) # Adding and deleting a place try: added_place = google_places.add_place(name='Mom and Pop local store', lat_lng={ 'lat': 51.501984, 'lng': -0.141792 }, accuracy=100, types=types.TYPE_HOME_GOODS_STORE, language=lang.ENGLISH_GREAT_BRITAIN) print added_place.place_id # The Google Places identifier - Important! print added_place.id # Delete the place that you've just added. google_places.delete_place(added_place.place_id) except GooglePlacesError as error_detail: # You've passed in parameter values that the Places API doesn't like.. print error_detail
def get(address): key = 'AIzaSyC5R4DhcOBRYguyefShsK8IwGpgEPbv3qY' google_places = GooglePlaces(key) # address = '546 West 113th Street, New York, NY' # You may prefer to use the text_search API, instead. query_result = google_places.nearby_search( # location='London, England', keyword='Fish and Chips', location=address, keyword='', radius=1610, types=[ types.TYPE_AMUSEMENT_PARK, types.TYPE_AQUARIUM, types.TYPE_ART_GALLERY, types.TYPE_MUSEUM, types.TYPE_ZOO, types.TYPE_POINT_OF_INTEREST ]) print(type(query_result)) # return json.dumps(query_result, ensure_ascii=False) # print('query result is: ' + query_result) if query_result.has_attributions: print query_result.html_attributions for place in query_result.places: # Returned places from a query are place summaries. print place.name print place.geo_location print place.reference # The following method has to make a further API call. place.get_details() # Referencing any of the attributes below, prior to making a call to # get_details() will raise a googleplaces.GooglePlacesAttributeError. print place.details # A dict matching the JSON response from Google. print place.local_phone_number print place.international_phone_number print place.website print place.url # Getting place photos for photo in place.photos: # 'maxheight' or 'maxwidth' is required photo.get(maxheight=500, maxwidth=500) # MIME-type, e.g. 'image/jpeg' photo.mimetype # Image URL photo.url # Original filename (optional) photo.filename # Raw image data photo.data # Adding and deleting a place try: added_place = google_places.add_place( name='Mom and Pop local store', lat_lng={ 'lat': 51.501984, 'lng': -0.141792 }, accuracy=100, types=types.TYPE_HOME_GOODS_STORE, language=lang.ENGLISH_GREAT_BRITAIN) print(added_place.reference ) # The Google Places reference - Important! print(added_place.id) # Delete the place that you've just added. google_places.delete_place(added_place.reference) except GooglePlacesError as error_detail: # You've passed in parameter values that the Places API doesn't like.. print(error_detail)
# Getting place photos for photo in place.photos: # 'maxheight' or 'maxwidth' is required photo.get(maxheight=500, maxwidth=500) # MIME-type, e.g. 'image/jpeg' photo.mimetype # Image URL photo.url # Original filename (optional) photo.filename # Raw image data photo.data # Adding and deleting a place try: added_place = google_places.add_place(name='Mom and Pop local store', lat_lng={'lat': 51.501984, 'lng': -0.141792}, accuracy=100, types=types.TYPE_HOME_GOODS_STORE, language=lang.ENGLISH_GREAT_BRITAIN) print added_place.reference # The Google Places reference - Important! print added_place.id # Delete the place that you've just added. google_places.delete_place(added_place.reference) except GooglePlacesError as error_detail: # You've passed in parameter values that the Places API doesn't like.. print error_detail
# API call. place.get_details() # Getting place photos for photo in place.photos: # 'maxheight' or 'maxwidth' is required photo.get(maxheight=500, maxwidth=500) # MIME-type, e.g. 'image/jpeg' var = photo.mimetype # Image URL var = photo.url # Original filename (optional) var = photo.filename # Raw image data var = photo.data # Adding and deleting a place try: added_place = google_places.add_place(name='Mom and Pop local store', lat_lng={'lat': 51.501984, 'lng': -0.141792}, accuracy=100, types=types.TYPE_HOME_GOODS_STORE, language=lang.ENGLISH_GREAT_BRITAIN) print(added_place.place_id) print(added_place.id) # Delete added place google_places.delete_place(added_place.place_id) except GooglePlacesError as error_detail: print(error_detail)