Last active
May 4, 2017 01:18
-
-
Save Santiago-j-s/0de2c001b5dc34542552c566cf696365 to your computer and use it in GitHub Desktop.
Datos Abiertos Chubut
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
import requests | |
import json | |
s = requests.Session() | |
response = s.get('http://datos.chubut.gov.ar/api/3/action/package_list') | |
package_list = response.json()['result'] | |
for package in package_list: | |
package_data = s.get(''.join(['http://datos.chubut.gov.ar/api/3/action/package_show?id=', package])) | |
recursos = package_data.json()['result']['resources'] | |
for recurso in recursos: | |
filename = ''.join([recurso['name'], '.', recurso['format'].lower()]) | |
r = s.get(recurso['url']) | |
with open(filename, 'xb') as f: | |
for chunk in r.iter_content(chunk_size=512*1024): | |
if chunk: | |
f.write(chunk) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment