Превышено максимальное количество повторов: геокодирование нескольких адресов и запись в Excel - PullRequest
0 голосов
/ 24 января 2020

Я пытаюсь геокодировать список адресов и добавить его в файл Excel, используя HERE API, но я сталкиваюсь с ошибкой, превышено максимальное количество повторов.

Вот мой текущий код:

def geocode(location):
    # api-endpoint 
    URL = "https://geocoder.ls.hereapi.com/6.2/geocode.json"

    # defining a params dict for the parameters to be sent to the API 
    PARAMS = {'searchtext':location, 'gen':9,'apiKey':"s"} 

    # sending get request and saving the response as response object 
    r = requests.get(url = URL, params = PARAMS) 

    if response.status_code == 200:
    # extracting data in json format 
    out = r.json() 

    try:

        area =   out['Response']['View'][0]['Result'][0]['Location']['Address']['County'] 
        city =   out['Response']['View'][0]['Result'][0]['Location']['Address']['City'] 
        zip  =   out['Response']['View'][0]['Result'][0]['Location']['Address']['PostalCode'] 

    except IndexError :

        area = ""
        city = ""
        zip = ""



    return out,area,city,zip

Вот мой l oop:

# Loop thru addresses

i = 1
for primary in primary_address:
   i = i + 1
   out,area,city,zip = geocode(primary) 
   sheet.cell(row=i, column=first_empty_col).value = area 
   sheet.cell(row=i, column=first_empty_col + 1).value = city
   sheet.cell(row=i, column=first_empty_col + 2).value = zip

book.save('file.xlsx')

Как мне сделать это наиболее эффективным способом?

1 Ответ

0 голосов
/ 24 января 2020

Для эффективного геокодирования большего числа местоположений вам следует взглянуть на Batch Geocoder API .

...