justice.cz search "API"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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') | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment