Last active
December 11, 2015 18:29
-
-
Save starenka/4641970 to your computer and use it in GitHub Desktop.
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 | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ;) )