Skip to content

Instantly share code, notes, and snippets.

@starenka starenka/
Last active Oct 6, 2018

What would you like to do?
# pip install requests xmltodict pandas
import datetime
import time
import os
import requests
import xmltodict
import pandas as pd
PRAHA = 554782
P7 = 500186
def parse(okr):
data = xmltodict.parse(requests.get(
'' % okr, timeout=10).content)
ucast = res['UCAST']
parties = res['VOLEBNI_STRANA']
parsed = {p['@NAZEV_STRANY']: (p['@ZASTUPITELE_POCET'], p['@HLASY_PROC'],
p['@HLASY'], p['@ZASTUPITELE_PROC']) for p in parties}
df = pd.DataFrame(parsed).T
df.columns = ('zas_mandatu', 'proc', 'hlasu', 'zas_proc')
df['proc'] = pd.to_numeric(df['proc'])
df['hlasu'] = pd.to_numeric(df['hlasu'])
df['zas_proc'] = pd.to_numeric(df['zas_proc'])
df['zas_mandatu'] = pd.to_numeric(df['zas_mandatu'])
sor = df.sort_values(['zas_mandatu', 'proc'], axis=0, ascending=False)
return sor, ucast
def show(okr, label):
data, ucast = parse(okr)
print '\n===== %s ===== \t\tzpracovano: %s%%\t ucast: %s%%' % (label, ucast['@OKRSKY_ZPRAC_PROC'], ucast['@UCAST_PROC'])
print data.head(10)
while True:
print 'data: %s' %
show(P7, 'PRAHA 7')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.