Skip to content

Instantly share code, notes, and snippets.

@Santiago-j-s
Last active May 4, 2017 01:18
Show Gist options
  • Save Santiago-j-s/0de2c001b5dc34542552c566cf696365 to your computer and use it in GitHub Desktop.
Save Santiago-j-s/0de2c001b5dc34542552c566cf696365 to your computer and use it in GitHub Desktop.
Datos Abiertos Chubut
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