Last active
June 29, 2018 09:44
-
-
Save matkoniecz/04a224799bc0fc05b3fb218d75b74acc to your computer and use it in GitHub Desktop.
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
import urllib.request, urllib.error, urllib.parse | |
import time | |
def download_overpass_query(query, filepath): | |
query = urllib.parse.quote(query) | |
url = "http://overpass-api.de/api/interpreter?data=" + query | |
with open(filepath, 'w') as file: | |
downloaded = overpass_download(url) | |
print(downloaded) | |
file.write(downloaded) | |
def overpass_download(url): | |
while True: | |
try: | |
print("downloading " + url) | |
resource = urllib.request.urlopen(url) | |
return resource.read().decode('utf-8') | |
except urllib.error.HTTPError as e: | |
print(e.getcode()) | |
if e.getcode() == 429 or e.getcode() == 503: | |
time.sleep(60) | |
continue | |
raise e | |
except urllib.error.URLError as e: | |
print(("URLError for url " + url)) | |
print(e) | |
return | |
query = """ | |
[out:json][timeout:25]; | |
( | |
node["flood_mark"="yes"]; | |
way["flood_mark"="yes"]; | |
relation["flood_mark"="yes"]; | |
); | |
out body; | |
>; | |
out skel qt; | |
""" | |
download_overpass_query(query, 'test_saving.geojson') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment