29 lines
No EOL
1.1 KiB
Python
29 lines
No EOL
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
deserialize json
|
|
"""
|
|
import json
|
|
class DeserializeJson:
|
|
def __init__(self, filename):
|
|
print("let's deserialize something")
|
|
tempdata = open(filename, encoding="utf8")
|
|
self.data = json.load(tempdata)
|
|
|
|
def somestats(self):
|
|
example_stat = 0
|
|
voivodeships = {}
|
|
for dep in self.data:
|
|
if dep['Województwo'] not in voivodeships:
|
|
voivodeships[dep['Województwo']] = {}
|
|
|
|
if dep['typ_JST'] not in voivodeships[dep["Województwo"]]:
|
|
voivodeships[dep['Województwo']][dep['typ_JST']] = 0
|
|
|
|
voivodeships[dep['Województwo']][dep['typ_JST']] += 1
|
|
if dep['typ_JST'] == 'GM' and dep['Województwo']== 'dolnośląskie':
|
|
example_stat += 1
|
|
print('liczba urzędów miejskich w województwie dolnośląskim: ' + ' ' + str(example_stat))
|
|
for voivodeship in voivodeships:
|
|
print('wojewodztwo ' + voivodeship + ': ')
|
|
for dep in voivodeships[voivodeship]:
|
|
print("typ " + dep + ": " + str(voivodeships[voivodeship][dep])) |