-
-
Save satai/4642199 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 = [] | |
for name, perc in zip(doc.find('table.left2 td[headers="s2a1 s2b2"]'), doc.find('table.left2 td.cislo[headers="s2a6 s2b6"]')): | |
try: | |
ret.append((name.text.encode('utf8'), to_float(perc))) | |
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%%' % (one[0], one[1])) | |
time.sleep(30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment