Skip to content

Instantly share code, notes, and snippets.

@kokes
Created January 13, 2018 12:58
Show Gist options
  • Save kokes/698de63072f558e607f3ad6d0ed5561a to your computer and use it in GitHub Desktop.
Save kokes/698de63072f558e607f3ad6d0ed5561a to your computer and use it in GitHub Desktop.
stahovani prubeznych vysledku
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