import requests import requests_cache import sys requests_cache.configure('/tmp/aaa') def get_rows(param, url='http://api.mojepanstwo.pl/dane/dataset/krs_podmioty/search.json'): def parse(r): for x in r['search']['dataobjects']: yield x['_id'] r = requests.get(url, params=param).json() yield from parse(r) for page in range(2, int(r['search']['pagination']['total']/20)): param['page'] = page r = requests.get(url, params=param).json() yield from parse(r) def parse_row(url, i): # print url x = requests.get(url, params={'layers': 'reprezentacja'}).json()['object'] d = x['data'] print('

%s. %s

' % (i, d['krs_podmioty.nazwa'], )) print('

') if not d['krs_podmioty.email'] == '------': print('Email: %s
' % (d['krs_podmioty.email'], d['krs_podmioty.email'])) print('Adres: %s
' % (d['krs_podmioty.adres'].replace(', lok. ---', ''), )) print('KRS: %s
' % (x['_mpurl'], d['krs_podmioty.krs'], )) if not d['krs_podmioty.nip'] == '0': print('NIP: %s
' % (d['krs_podmioty.nip'], )) if not d['krs_podmioty.regon'] == '0': print('REGON: %s
' % (d['krs_podmioty.regon'], )) print('Forma prawna: %s
' % (d['krs_podmioty.forma_prawna_str'], )) if not d['krs_podmioty.www'] == '------': print('WWW: %s
' % (d['krs_podmioty.www'], d['krs_podmioty.www'], )) if x['layers']['reprezentacja']: print('Reprezentacja:

') else: print('

') print('') print(""" """) if sys.argv[1] == '1': param = {'conditions[gmina_id]': '1854', 'conditions[rejestr]': '2'} if sys.argv[1] == '2': param = {'conditions[gmina_id]': '769', 'conditions[rejestr]': '2'} if sys.argv[1] == '3': param = {'conditions[gmina_id]': '769'} if sys.argv[1] == '4': param = {'conditions[gmina_id]': '1854'} # param = {'conditions[gmina_id]': '1854', } for i, row in enumerate(get_rows(param)): parse_row(row, i+1) print(""" """)