Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
get all possible cities for a postal code in the given country.
# -*- coding: utf-8 -*-
from console import alert
from json import loads
from sys import argv, exit
from urllib import urlopen, quote
import webbrowser
def error_dialog(title, message):
a diaolog box for error messages.
alert(title, message)
except KeyboardInterrupt:
def handle_data(data):
process json response from zippopotamus.
will return a markdown list of items.
city_json = loads(data)
output = ''
for item in city_json['places']:
output += '- Ort: {place}, Region: {state}\n'.format(place=item['place name'], state=item['state'])
return output
def get_by_postalcode(data):
get all possible cities for a postal code in
the given country.
api_url_base = '{country}/{postcode}'
postcode_, country_= [item.strip() for item in data.split(',')]
except Exception as err:
error_dialog(str(err.__class__), err.message)
response = urlopen(api_url_base.format(country=country_, postcode=postcode_))
except IOError:
error_dialog('Connection Error', 'Unable to perform request.')
if response.getcode() == 200:
postcode_data = handle_data('drafts://x-callback-url/create?text={0}'.format(quote(postcode_data)))
error_dialog('Error', 'Status code: {0} - Message: {1}'.format(response.getcode(),
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment