Advertisement
Guest User

Gardens Python

a guest
Nov 24th, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. import json
  2. import csv
  3. soubor = open('gardens.json', encoding='utf-8')
  4. data = soubor.read()
  5. gardens = json.loads(data)
  6. writer = csv.writer(open("gardens.csv", 'w', newline='', encoding='utf-8'))
  7. writer.writerow(['latitude','longitude','id','name','address','district','url','restaurace','wc','misto','mhd','sport','brusle','cesty','provoz','kolo','hriste','parking','doba'])
  8. for g in gardens['features']:
  9.   latitude = g['geometry']['coordinates'][1]
  10.   longitude = g['geometry']['coordinates'][0]
  11.   parkid = g['properties']['id']
  12.   name = g['properties']['name']
  13.   address = g['properties']['address']
  14.   district = g['properties']['district']
  15.   url = g['properties']['url']
  16.   items = g['properties']['properties']
  17.   restaurace = None
  18.   for i in items:
  19.     v = i['id']
  20.     if v == 'restaurace':
  21.       restaurace = i['value']
  22.     if v == 'wc':
  23.       wc = i['value']
  24.     if v == 'misto':
  25.       misto = i['value']
  26.     if v == 'mhd':
  27.       mhd = i['value']
  28.     if v == 'sport':
  29.       sport = i['value']
  30.     if v == 'brusle':
  31.       brusle = i['value']
  32.     if v == 'cesty':
  33.       cesty = i['value']
  34.     if v == 'provoz':
  35.       provoz = i['value']
  36.     if v == 'kolo':
  37.       kolo = i['value']
  38.     if v == 'hriste':
  39.       hriste = i['value']
  40.     if v == 'parking':
  41.       parking = i['value']
  42.     if v == 'doba':
  43.       doba = i['value']
  44.   writer.writerow([latitude, longitude,parkid,name,address,district,url,restaurace,wc,misto,mhd,sport,brusle,cesty,provoz,kolo,hriste,parking,doba])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement