Created
June 1, 2017 19:42
-
-
Save frafra/b7c2bfded15d2b95b3a9a127c4953465 to your computer and use it in GitHub Desktop.
Simple script which converts address to coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import json | |
import urllib.parse | |
import urllib.request | |
BASE = 'http://dev.virtualearth.net/REST/v1/Locations?' | |
parser = argparse.ArgumentParser() | |
parser.add_argument('key') | |
parser.add_argument('file', type=argparse.FileType('r', encoding='UTF-8')) | |
args = parser.parse_args() | |
query = { | |
'key':args.key, | |
'maxResults':1, | |
} | |
for line in args.file.readlines(): | |
query['query'] = line.strip() | |
url = BASE+urllib.parse.urlencode(query) | |
response = urllib.request.urlopen(url).read().decode("utf-8") | |
result = json.loads(response) | |
point = result['resourceSets'][0]['resources'][0]['point']['coordinates'] | |
print(line.strip()+': '+','.join(map(str, point))) | |
args.file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment