def testGoogleDetails(self): google = Google(storage=DictionaryStorage()) place_id = u'ChIJL9V5DTEQzkwR2Iz9nMnPGkc' details_response = google.details(place_id) self.assertIsNotNone(details_response) details_response_again = google.details(place_id) self.assertIsNotNone(details_response_again)
class GoogleDetails(CherryPickerBase): def __init__(self, source=None, storage=None, request_handler=None): super(GoogleDetails, self).__init__(source, storage, request_handler) if not source: self.source = Google(storage=storage, request_handler=request_handler) def __call__(self, howdy_model, force=False): """ Parse the google text search results and set the correct attributes. """ google_details_result = self.source.details(howdy_model['google_places_id'], force) self.parse_result(google_details_result, howdy_model) def parse_result(self, result, howdy_model): """ """ website = result.get('website', None) domain = None if website: domain = urlparse(website).hostname howdy_model['website'] = website howdy_model['domain'] = domain howdy_model['utc_offset'] = result.get('utc_offset', None) howdy_model['formatted_address'] = result.get('formatted_address', None)
class GoogleTextSearch(CherryPickerBase): def __init__(self, source=None, storage=None, request_handler=None): super(GoogleTextSearch, self).__init__(source, storage, request_handler) if not source: self.source = Google(storage=storage, request_handler=request_handler) def __call__(self, caller_id, force=False): """ Parse the google text search results and set the correct attributes. """ google_text_search_results = self.source.text_search(caller_id, force) or [] howdy_results = [] for search_result in google_text_search_results: howdy_model = {} self.parse_result(search_result, howdy_model) howdy_results.append(howdy_model) return howdy_results def parse_result(self, result, howdy_model): howdy_model['google_places_id'] = result.get('place_id', None) howdy_model['name'] = result.get('name', None) geometry = result.get('geometry', None) howdy_model['location'] = geometry.get('location', None) if geometry else None
class GooglePlacesTest(unittest.TestCase): def setUp(self): self.google = Google() ############################## #### GOOGLE PLACES SEARCH #### ############################## def test_search_caller_id(self): caller_id = 16132379329 results = self.google.text_search(caller_id) self.assertIsNotNone(results) def test_search_caller_id_not_found(self): caller_id = 16133246100 self.assertRaises(Exception, self.google.text_search, caller_id) def test_place_id_request(self): place_id = u'ChIJL9V5DTEQzkwR2Iz9nMnPGkc' result = self.google.details(place_id) self.assertIsNotNone(result) self.assertEqual(result.get('website', None), 'http://www.versature.com/')
def __init__(self, source=None, storage=None, request_handler=None): super(GoogleDetails, self).__init__(source, storage, request_handler) if not source: self.source = Google(storage=storage, request_handler=request_handler)
def setUp(self): self.google = Google()