Created
January 13, 2018 12:58
-
-
Save kokes/698de63072f558e607f3ad6d0ed5561a to your computer and use it in GitHub Desktop.
stahovani prubeznych vysledku
This file contains hidden or 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
from urllib.request import urlopen | |
from datetime import datetime | |
import base64 | |
import time | |
url = 'https://www.volby.cz/pls/prez2018/vysledky' | |
pause = 15 | |
while True: | |
time.sleep(pause) | |
now = datetime.now().isoformat() | |
print('stahuju', now, end='\r') | |
try: | |
with urlopen(url) as r: | |
data = base64.b64encode(r.read()).decode('ascii') | |
except: | |
print('dl failed', now) | |
continue | |
tfn = 'data_%s.csv' % datetime.now().strftime('%H') | |
with open(tfn, 'a+') as fw: | |
fw.write('%s,%s\n' % (now, data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment