Buy Me a Coffee? Your support is much appreciated!
PayPal Me: https://www.paypal.me/jiejenn/5
Venmo: @Jie-Jenn
Source Code:
from pprint import pprint import os import googlemaps # pip install googlemaps import win32com.client as win32 API_KEY = open('API_KEY.txt').read() map_client = googlemaps.Client(API_KEY) def get_place_info(location_name): try: # location_name = 'Lanxess Arena Köln' response = map_client.places(query=location_name) results = response.get('results')[0] return results except Exception as e: print(e) return None xlApp = win32.Dispatch('Excel.Application') xlApp.Visible = True wb = xlApp.workbooks.open(os.path.join(os.getcwd(), 'Copy of output.xlsx')) wsList = wb.Worksheets('List') LastRow = wsList.Cells(wsList.Rows.Count, 'A').End(-4162).Row for i in range(2, LastRow+1): place_info = get_place_info(wsList.Cells(i, 1).Value) wsList.cells(i, 2).Value = place_info['name'] wsList.cells(i, 3).Value = place_info['formatted_address'] wsList.cells(i, 4).Value = place_info['place_id'] wsList.cells(i, 5).Value = place_info['rating'] wsList.cells(i, 6).Value = place_info['user_ratings_total'] wb = None wsList = None xlApp = None
Hi, I’ve been searching for a tutorial to search business names and return the address and your video is perfect. I hit a little snag though.
I’m getting this “TypeError: ‘NoneType’ object is not subscriptable” when the business name doesn’t return a result. Is there a way to just have something returned like “not found” and then move to the next?
Hi,
Traceback (most recent call last):
File “C:\Users\exa\Desktop\py.py”, line 31, in
wsList.cells(i, 6).Value = place_info[‘formatted_phone_number’]
KeyError: ‘formatted_phone_number’
I want to get the phone number of the business.