|
|
@ -25,6 +25,14 @@ class VisuFile:
|
|
|
|
def __exit__(self, _et, _ev, _tb):
|
|
|
|
def __exit__(self, _et, _ev, _tb):
|
|
|
|
plt.savefig(self.filename, format='pdf')
|
|
|
|
plt.savefig(self.filename, format='pdf')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VisuInter:
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
plt.ion()
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
|
|
|
|
plt.clf()
|
|
|
|
|
|
|
|
def __exit__(self, _et, _ev, _tb):
|
|
|
|
|
|
|
|
plt.show(block=False)
|
|
|
|
|
|
|
|
|
|
|
|
def get_xml():
|
|
|
|
def get_xml():
|
|
|
|
URL=r'https://www.volby.cz/pls/prez2023/vysledky'
|
|
|
|
URL=r'https://www.volby.cz/pls/prez2023/vysledky'
|
|
|
|
response = requests.get(URL)
|
|
|
|
response = requests.get(URL)
|
|
|
@ -65,7 +73,7 @@ def fill_data(vysl) -> tuple[datetime, dict[str, int]]:
|
|
|
|
return vysl.timestamp, vysl.kandidati
|
|
|
|
return vysl.timestamp, vysl.kandidati
|
|
|
|
|
|
|
|
|
|
|
|
def plot(ts, kand):
|
|
|
|
def plot(ts, kand):
|
|
|
|
with VisuFile('/tmp/volby.pdf'):
|
|
|
|
with VisuInter():
|
|
|
|
order = (
|
|
|
|
order = (
|
|
|
|
'Petr Pavel',
|
|
|
|
'Petr Pavel',
|
|
|
|
'Danuše Nerudová',
|
|
|
|
'Danuše Nerudová',
|
|
|
@ -110,4 +118,9 @@ def visu_once():
|
|
|
|
ts, k = fill_data(v)
|
|
|
|
ts, k = fill_data(v)
|
|
|
|
plot(ts, k)
|
|
|
|
plot(ts, k)
|
|
|
|
|
|
|
|
|
|
|
|
visu_once()
|
|
|
|
def loop(refresh=30):
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
visu_once()
|
|
|
|
|
|
|
|
plt.pause(refresh)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loop()
|
|
|
|