Created
September 24, 2015 13:08
-
-
Save wprzyb/d98739f4439916945419 to your computer and use it in GitHub Desktop.
kodypocztowe
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 python | |
# -*- coding: utf-8 -*- | |
import urllib, json | |
for i in range(1,450): | |
url = "https://api-v3.mojepanstwo.pl/dane/kody_pocztowe.json?page=%s" % i | |
print("\n\tPrzetwarzam strone nr %i" % i) | |
response = urllib.urlopen(url) | |
data = json.loads(response.read()) | |
length = len(data["Dataobject"]) | |
for j in range(0,length): | |
id = data["Dataobject"][j]["data"]["kody_pocztowe.id"] | |
mie = data["Dataobject"][j]["data"]["kody_pocztowe.miejscowosci_str"] | |
gmi = data["Dataobject"][j]["data"]["kody_pocztowe.gminy_str"] | |
kod = data["Dataobject"][j]["data"]["kody_pocztowe.kod"] | |
file = open('kody.list', 'w') | |
file.write("%s,%s,%s,%s\n" % (id,(mie.encode("utf8")),(gmi.encode("utf8")),kod) ) | |
file.close() | |
print(j), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment