Created
May 13, 2012 05:17
-
-
Save imankulov/2682643 to your computer and use it in GitHub Desktop.
Simple wrapper around nominatim geocoding web service
This file contains hidden or 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 python | |
# -*- coding: utf-8 -*- | |
import httplib2 | |
import urllib | |
import json | |
def request(address, email=None, limit=None): | |
""" | |
Simple wrapper around nominatim geocoding web service | |
See http://wiki.openstreetmap.org/wiki/Nominatim | |
""" | |
base_url = 'http://nominatim.openstreetmap.org/search' | |
h = httplib2.Http('.cache') | |
query = {'q': address, 'format': 'json'} | |
if limit: | |
query['limit'] = limit | |
if email: | |
query['email'] = email | |
query_string = urllib.urlencode(query) | |
resp, content = h.request('{0}?{1}'.format(base_url, query_string)) | |
return json.loads(content) | |
if __name__ == '__main__': | |
import argparse | |
import pprint | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-e', '--email', help='Your email') | |
parser.add_argument('-l', '--limit', type=int, help='Result limit') | |
parser.add_argument('address', nargs=1, help='Address you want to convert') | |
args = parser.parse_args() | |
pprint.pprint(request(args.address, args.email, args.limit)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment