Skip to content

Instantly share code, notes, and snippets.

@osya
Last active July 18, 2016 18:24
Show Gist options
  • Save osya/41d57377729cd1b95b85 to your computer and use it in GitHub Desktop.
Save osya/41d57377729cd1b95b85 to your computer and use it in GitHub Desktop.
Example of using openpyxl & geopy #geopy #openpyxl
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from geopy.geocoders import Yandex
from openpyxl import load_workbook
filename = 'realty.xlsx'
wb = load_workbook(filename)
ws = wb.get_sheet_by_name('data')
geolocator = Yandex()
iterrows = ws.iter_rows()
next(iterrows)
for i,row in enumerate(iterrows):
cell = row[2]
location = geolocator.geocode(cell.value)
AdministrativeArea = location.raw['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['AdministrativeAreaName']
row[1].value = AdministrativeArea
wb.save(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment