diff --git a/poc.py b/poc.py index b437feb..fda8a5b 100755 --- a/poc.py +++ b/poc.py @@ -25,6 +25,14 @@ class VisuFile: def __exit__(self, _et, _ev, _tb): 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(): URL=r'https://www.volby.cz/pls/prez2023/vysledky' response = requests.get(URL) @@ -65,7 +73,7 @@ def fill_data(vysl) -> tuple[datetime, dict[str, int]]: return vysl.timestamp, vysl.kandidati def plot(ts, kand): - with VisuFile('/tmp/volby.pdf'): + with VisuInter(): order = ( 'Petr Pavel', 'Danuše Nerudová', @@ -110,4 +118,9 @@ def visu_once(): ts, k = fill_data(v) plot(ts, k) -visu_once() +def loop(refresh=30): + while True: + visu_once() + plt.pause(refresh) + +loop()