Skip to content

Instantly share code, notes, and snippets.

@motiejus
Created November 17, 2016 20:10
Show Gist options
  • Save motiejus/7aae182cb6b44366de5a2657a8f2a4ab to your computer and use it in GitHub Desktop.
Save motiejus/7aae182cb6b44366de5a2657a8f2a4ab to your computer and use it in GitHub Desktop.
Vilniaus Darželiai
"""Parses KML file from the google map of http://www.vilnius.lt/darzeliai/info/.
Outputs a spreasheet-importable CSV.
"""
import sys
import csv
import xmltodict
def main():
with open("privatus.xml") as f:
x = f.read()
top = xmltodict.parse(x)
ret = []
for d in top['kml']['Document']['Placemark']:
i = {'name': d['name']}
for nameval in d['ExtendedData']['Data']:
k = nameval['@name']
v = nameval['value']
i[k] = v
ret.append(i)
return ret
if __name__ == '__main__':
ds = main()
fieldnames = [
'name',
'Visos studijų ar mokymo kalbos',
'Interneto svetainės adresas',
'Telefonas',
'El. paštas',
'Adresas',
'Vadovas'
]
writer = csv.DictWriter(sys.stdout, fieldnames=fieldnames, extrasaction='ignore')
writer.writeheader()
for d in ds:
writer.writerow(d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment