zad 1->6
This commit is contained in:
commit
737e013ecf
12 changed files with 204022 additions and 0 deletions
311
.gitignore
vendored
Normal file
311
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,311 @@
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# UV
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
#uv.lock
|
||||||
|
|
||||||
|
# poetry
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||||
|
#poetry.lock
|
||||||
|
|
||||||
|
# pdm
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||||
|
#pdm.lock
|
||||||
|
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||||
|
# in version control.
|
||||||
|
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
||||||
|
.pdm.toml
|
||||||
|
.pdm-python
|
||||||
|
.pdm-build/
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
# PyCharm
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
|
|
||||||
|
# Ruff stuff:
|
||||||
|
.ruff_cache/
|
||||||
|
|
||||||
|
# PyPI configuration file
|
||||||
|
.pypirc
|
||||||
|
|
||||||
|
|
||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
|
||||||
|
[Dd]ebug/
|
||||||
|
[Rr]elease/
|
||||||
|
x64/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_i.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.log
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.Publish.xml
|
||||||
|
*.pubxml
|
||||||
|
*.azurePubxml
|
||||||
|
|
||||||
|
# NuGet Packages Directory
|
||||||
|
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
|
||||||
|
packages/
|
||||||
|
## TODO: If the tool you use requires repositories.config, also uncomment the next line
|
||||||
|
!packages/repositories.config
|
||||||
|
|
||||||
|
# Windows Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Windows Store app package directory
|
||||||
|
AppPackages/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
sql/
|
||||||
|
*.Cache
|
||||||
|
ClientBin/
|
||||||
|
[Ss]tyle[Cc]op.*
|
||||||
|
![Ss]tyle[Cc]op.targets
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
|
||||||
|
*.publishsettings
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file to a newer
|
||||||
|
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
App_Data/*.mdf
|
||||||
|
App_Data/*.ldf
|
||||||
|
|
||||||
|
# =========================
|
||||||
|
# Windows detritus
|
||||||
|
# =========================
|
||||||
|
|
||||||
|
# Windows image file caches
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
Desktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Mac desktop service store files
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
_NCrunch*
|
||||||
|
|
||||||
|
.idea/
|
||||||
13
IS_Lab2_JSON/Assets/basic_config.yaml
Normal file
13
IS_Lab2_JSON/Assets/basic_config.yaml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
paths:
|
||||||
|
source_folder: 'Assets/'
|
||||||
|
json_source_file: 'data.json'
|
||||||
|
yaml_source_file: 'data.yaml'
|
||||||
|
json_destination_file: 'data_mod2.json'
|
||||||
|
yaml_destination_file: 'data_ymod2.yaml'
|
||||||
|
|
||||||
|
launch:
|
||||||
|
operations:
|
||||||
|
- 'deserialize'
|
||||||
|
- 'serialize'
|
||||||
|
- 'convert'
|
||||||
|
source: 'file'
|
||||||
65023
IS_Lab2_JSON/Assets/data.json
Normal file
65023
IS_Lab2_JSON/Assets/data.json
Normal file
File diff suppressed because it is too large
Load diff
59383
IS_Lab2_JSON/Assets/data.yaml
Normal file
59383
IS_Lab2_JSON/Assets/data.yaml
Normal file
File diff suppressed because it is too large
Load diff
1
IS_Lab2_JSON/Assets/data_mod.json
Normal file
1
IS_Lab2_JSON/Assets/data_mod.json
Normal file
File diff suppressed because one or more lines are too long
1
IS_Lab2_JSON/Assets/data_mod2.json
Normal file
1
IS_Lab2_JSON/Assets/data_mod2.json
Normal file
File diff suppressed because one or more lines are too long
19790
IS_Lab2_JSON/Assets/data_ymod.yaml
Normal file
19790
IS_Lab2_JSON/Assets/data_ymod.yaml
Normal file
File diff suppressed because it is too large
Load diff
59383
IS_Lab2_JSON/Assets/data_ymod2.yaml
Normal file
59383
IS_Lab2_JSON/Assets/data_ymod2.yaml
Normal file
File diff suppressed because it is too large
Load diff
18
IS_Lab2_JSON/convert_json_to_yaml.py
Normal file
18
IS_Lab2_JSON/convert_json_to_yaml.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
json to yaml converter
|
||||||
|
"""
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
from deserialize_json import DeserializeJson
|
||||||
|
|
||||||
|
class ConvertJsonToYaml:
|
||||||
|
@staticmethod
|
||||||
|
def run(deserializeddata, destinationfilelocaiton):
|
||||||
|
if type(deserializeddata) is str and deserializeddata.endswith('.json'):
|
||||||
|
deserializeddata = DeserializeJson(deserializeddata)
|
||||||
|
if type(deserializeddata) is DeserializeJson:
|
||||||
|
deserializeddata = deserializeddata.data
|
||||||
|
with open(destinationfilelocaiton, 'w', encoding='utf-8') as f:
|
||||||
|
yaml.dump(deserializeddata, f, allow_unicode=True)
|
||||||
|
print("it is done")
|
||||||
29
IS_Lab2_JSON/deserialize_json.py
Normal file
29
IS_Lab2_JSON/deserialize_json.py
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
# -*- 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]))
|
||||||
45
IS_Lab2_JSON/main.py
Normal file
45
IS_Lab2_JSON/main.py
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
from deserialize_json import DeserializeJson
|
||||||
|
from serialize_json import SerializeJson
|
||||||
|
from convert_json_to_yaml import ConvertJsonToYaml
|
||||||
|
|
||||||
|
tempconffile = open('Assets/basic_config.yaml', encoding="utf8")
|
||||||
|
confdata = yaml.load(tempconffile, Loader=yaml.FullLoader)
|
||||||
|
tempconffile.close()
|
||||||
|
|
||||||
|
def deserialize():
|
||||||
|
global newDeserializator
|
||||||
|
newDeserializator = DeserializeJson(confdata['paths']['source_folder']+confdata['paths']['json_source_file'])
|
||||||
|
newDeserializator.somestats()
|
||||||
|
|
||||||
|
def serialize(source):
|
||||||
|
global newDeserializator
|
||||||
|
if source == "object":
|
||||||
|
SerializeJson.run(newDeserializator, confdata['paths']['source_folder']+confdata['paths']['json_destination_file'])
|
||||||
|
elif source == "file":
|
||||||
|
newDeserializator = DeserializeJson(confdata['paths']['source_folder']+confdata['paths']['json_source_file'])
|
||||||
|
SerializeJson.run(newDeserializator, confdata['paths']['source_folder']+confdata['paths']['json_destination_file'])
|
||||||
|
else:
|
||||||
|
print("invalid source")
|
||||||
|
|
||||||
|
def convert(source):
|
||||||
|
if source == "object":
|
||||||
|
ConvertJsonToYaml.run(newDeserializator, confdata['paths']['source_folder']+confdata['paths']['yaml_destination_file'])
|
||||||
|
elif source == "file":
|
||||||
|
ConvertJsonToYaml.run(confdata['paths']['source_folder']+confdata['paths']['json_source_file'], confdata['paths']['source_folder']+confdata['paths']['yaml_destination_file'])
|
||||||
|
else:
|
||||||
|
print("invalid source")
|
||||||
|
|
||||||
|
ops = {
|
||||||
|
'deserialize': deserialize,
|
||||||
|
'serialize': serialize,
|
||||||
|
'convert': convert
|
||||||
|
}
|
||||||
|
|
||||||
|
for operation in confdata['launch']['operations']:
|
||||||
|
if operation in ops:
|
||||||
|
if operation == "serialize" or operation == "convert":
|
||||||
|
ops[operation](confdata['launch']['source'])
|
||||||
|
else:
|
||||||
|
ops[operation]()
|
||||||
25
IS_Lab2_JSON/serialize_json.py
Normal file
25
IS_Lab2_JSON/serialize_json.py
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
serialize json
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
|
||||||
|
class SerializeJson:
|
||||||
|
#metoda statyczna
|
||||||
|
@staticmethod
|
||||||
|
def run(deserializeddata, filelocation):
|
||||||
|
print("let's serialize something")
|
||||||
|
lst = []
|
||||||
|
for dep in deserializeddata.data:
|
||||||
|
lst.append({
|
||||||
|
"Kod_TERYT": dep['Kod_TERYT'],
|
||||||
|
"Województwo": dep['Województwo'],
|
||||||
|
"Powiat": dep['Powiat'],
|
||||||
|
"typ_JST": dep['typ_JST'],
|
||||||
|
"nazwa_urzędu_JST": dep['nazwa_urzędu_JST'],
|
||||||
|
"miejscowość": dep['miejscowość'],
|
||||||
|
"telefon_z_numerem_kierunkowym": f'{str(dep["telefonkierunkowy"]).strip()}{str(dep["telefon"]).strip()}'
|
||||||
|
})
|
||||||
|
jsontemp = {"departaments": lst}
|
||||||
|
with open(filelocation, 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(jsontemp, f, ensure_ascii=False)
|
||||||
Loading…
Reference in a new issue