Advertisement
ganryu

Untitled

May 3rd, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. import requests
  2. import json
  3.  
  4. s = requests.Session()
  5. response = s.get('http://datos.chubut.gov.ar/api/3/action/package_list')
  6.  
  7. package_list = response.json()['result']
  8.  
  9. for package in package_list:
  10.     package_data = s.get(''.join(['http://datos.chubut.gov.ar/api/3/action/package_show?id=', package]))
  11.     recursos = package_data.json()['result']['resources']
  12.     for recurso in recursos:
  13.         filename = ''.join([recurso['name'], '.', recurso['format'].lower()])
  14.         r = s.get(recurso['url'])
  15.         with open(filename, 'xb')  as f:
  16.             for chunk in r.iter_content(chunk_size=512*1024):
  17.                 if chunk:
  18.                     f.write(chunk)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement