public
Created

justice.cz search "API"

  • Download Gist
justicepy.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
from pyquery import PyQuery as pq
 
class JusticePy(object):
URL = 'http://www.justice.cz/xqw/xervlet/insl/index?sysinf.%%40typ=or&sysinf.%%40strana=searchResults&hledani.%%40typ=subjekt&hledani.podminka.subjekt=%(subject)s&hledani.podminka.ico=%(ic)s&hledani.podminka.obec=&hledani.podminka.spisZnacka.oddil=&hledani.podminka.spisZnacka.vlozka=&hledani.podminka.spisZnacka.soud=0&hledani.format.pocet_polozek=50&hledani.format.trideni=netridit&hledani.format.typHledani=x*&hledani.format.obchodniJmeno=platne&hledani.podminka.pravniForma=-1&hledani.podminka.ulice='
ALLOWED = ('subject', 'ic')
 
def search(self, **kwargs):
sprints = {}
for one in self.ALLOWED:
sprints[one] = ''
sprints.update(kwargs)
doc = pq(url=self.URL % sprints)
return self._parse_result(doc)
 
def _parse_result(self, html):
parsed = []
for one in pq(html).find('img.cara + table + table'):
parsed.append(self._parse_one(one))
return parsed
 
def _parse_one(self, item):
keys = ('court_id', 'subject', 'ic', 'address', 'from')
parsed = {}
for pos, one in enumerate(pq(item).find('tr td')[1::2]):
parsed[keys[pos]] = pq(one).text()
return parsed
 
'''
if __name__ == '__main__':
print JusticePy().search(subject='construct')
'''

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.