Skip to content

Instantly share code, notes, and snippets.

@starenka
Last active December 11, 2015 18:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save starenka/4641970 to your computer and use it in GitHub Desktop.
Save starenka/4641970 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import time
from pyquery import PyQuery as pq
while True:
def to_float(text):
return float(text.text.replace(',', '.'))
doc = pq(url='http://www.volby.cz/pls/prez2013/pe2?xjazyk=CZ')
ret = []
ns, ps, vs = 'table.left2 td[headers="s2a1 s2b2"]', 'table.left2 td.cislo[headers="s2a6 s2b6"]', 'table.left2 td.cislo[headers="s2a5 s2b4"]'
for name, perc, votes in zip(doc.find(ns), doc.find(ps), doc.find(vs)):
try:
ret.append((name.text.encode('utf8'), to_float(perc), votes.text.encode('utf8')))
except ValueError:
continue
ret.sort(key=lambda one: one[1], reverse=True)
print '\nSECTENO: %s%%\n' % to_float(doc.find('td[headers="r12 s1a1 s1b3"]')[0])
for one in ret:
print '%s\t%s%%\t%s hlasu' % (one[0], one[1], one[2])
time.sleep(30)
@satai
Copy link

satai commented Jan 26, 2013

Koukam, ze na gistu nejde udelat pull request.
V https://gist.github.com/4642199 mas upravu, co funguje i s py3 (cti: pridal jsem zavorky ;) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment