krs-index.py

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('<h3>%s. %s</h3>' % (i, d['krs_podmioty.nazwa'], ))
    print('<p>')
    if not d['krs_podmioty.email'] == '------':
        print('<b>Email</b>: <a href="mailto:%s">%s</a><br>' % (d['krs_podmioty.email'],
                                                         d['krs_podmioty.email']))
    print('<b>Adres</b>: %s<br>' % (d['krs_podmioty.adres'].replace(', lok. ---', ''), ))
    print('<b>KRS</b>: <a href="%s">%s</a><br>' % (x['_mpurl'], d['krs_podmioty.krs'], ))
    if not d['krs_podmioty.nip'] == '0':
        print('<b>NIP</b>: %s<br>' % (d['krs_podmioty.nip'], ))
    if not d['krs_podmioty.regon'] == '0':
        print('<b>REGON</b>: %s<br>' % (d['krs_podmioty.regon'], ))
    print('<b>Forma prawna</b>: %s<br>' % (d['krs_podmioty.forma_prawna_str'], ))
    if not d['krs_podmioty.www'] == '------':
        print('<b>WWW</b>: <a href="http://%s">%s</a><br>' % (d['krs_podmioty.www'],
                                                       d['krs_podmioty.www'], ))
    if x['layers']['reprezentacja']:
        print('<b>Reprezentacja</b>:</p><ul>')
        for osoba in x['layers']['reprezentacja']:
            print("\t<li>%s - %s</li>" % (osoba['nazwa'], osoba['funkcja']))
        print('</ul>')
    else:
        print('</p>')
    print('')

print("""<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  </head>
<body>""")

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("""  </body>
</html>""")

it/krs-index.txt · ostatnio zmienione: 2015/02/23 15:47 przez naczelnik
Public Domain
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0

Fatal error: Cannot redeclare geoip_country_code_by_name() in /home/zenvanta/domains/jawne.info.pl/public_html/dostep/lib/plugins/quickstats/GEOIP/geoip.inc on line 347