Skip to content

Instantly share code, notes, and snippets.

@satai
Forked from starenka/volby2.py
Last active December 11, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satai/4642199 to your computer and use it in GitHub Desktop.
Save satai/4642199 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 = []
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