katottglib 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- katottglib-0.1.0/LICENSE +21 -0
- katottglib-0.1.0/PKG-INFO +35 -0
- katottglib-0.1.0/README.rst +19 -0
- katottglib-0.1.0/data/__init__.py +3 -0
- katottglib-0.1.0/data/data.py +37 -0
- katottglib-0.1.0/data/entity.py +18 -0
- katottglib-0.1.0/katottglib.egg-info/PKG-INFO +35 -0
- katottglib-0.1.0/katottglib.egg-info/SOURCES.txt +13 -0
- katottglib-0.1.0/katottglib.egg-info/dependency_links.txt +1 -0
- katottglib-0.1.0/katottglib.egg-info/top_level.txt +2 -0
- katottglib-0.1.0/pyproject.toml +26 -0
- katottglib-0.1.0/setup.cfg +25 -0
- katottglib-0.1.0/setup.py +3 -0
- katottglib-0.1.0/test/__init__.py +41 -0
katottglib-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Denis Senchishen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: katottglib
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python lib to operate KATOTTG addresses (classified administrative division of Ukraine).
|
|
5
|
+
Home-page: https://github.com/sen-den/katottglib
|
|
6
|
+
Author: Denis Senchishen
|
|
7
|
+
Author-email: dsenchishen@icloud.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Description-Content-Type: text/x-rst
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
|
|
17
|
+
===========
|
|
18
|
+
KATOTTG lib
|
|
19
|
+
===========
|
|
20
|
+
|
|
21
|
+
Quick start
|
|
22
|
+
-----------
|
|
23
|
+
|
|
24
|
+
To be done...
|
|
25
|
+
|
|
26
|
+
Release notes
|
|
27
|
+
-------------
|
|
28
|
+
|
|
29
|
+
v0.1.0 (2023-06-10)
|
|
30
|
+
...................
|
|
31
|
+
|
|
32
|
+
Initial release.
|
|
33
|
+
|
|
34
|
+
- Search by name with filter by level (``find_by_name``).
|
|
35
|
+
- Search by identifier (``find_by_id``)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
===========
|
|
2
|
+
KATOTTG lib
|
|
3
|
+
===========
|
|
4
|
+
|
|
5
|
+
Quick start
|
|
6
|
+
-----------
|
|
7
|
+
|
|
8
|
+
To be done...
|
|
9
|
+
|
|
10
|
+
Release notes
|
|
11
|
+
-------------
|
|
12
|
+
|
|
13
|
+
v0.1.0 (2023-06-10)
|
|
14
|
+
...................
|
|
15
|
+
|
|
16
|
+
Initial release.
|
|
17
|
+
|
|
18
|
+
- Search by name with filter by level (``find_by_name``).
|
|
19
|
+
- Search by identifier (``find_by_id``)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def load_xlsx() -> pd.DataFrame:
|
|
7
|
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
8
|
+
file_path = os.path.join(script_dir, "kodifikator.xlsx")
|
|
9
|
+
df = pd.read_excel(file_path, skiprows=2, skipfooter=3)
|
|
10
|
+
return df
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def load_data() -> pd.DataFrame:
|
|
14
|
+
df = load_xlsx()
|
|
15
|
+
df["id"] = df["Додатковий рівень"].fillna(
|
|
16
|
+
df["Четвертий рівень"].fillna(
|
|
17
|
+
df["Третій рівень"].fillna(
|
|
18
|
+
df["Другий рівень"].fillna(df["Перший рівень"])
|
|
19
|
+
)
|
|
20
|
+
)
|
|
21
|
+
)
|
|
22
|
+
category_mapping = {
|
|
23
|
+
"O": "Області та АРК",
|
|
24
|
+
"K": "Міста зі спеціальним статусом (Київ та Севастополь)",
|
|
25
|
+
"P": "Райони в областях та в АРК",
|
|
26
|
+
"H": "Територіальні громади",
|
|
27
|
+
"M": "Міста",
|
|
28
|
+
"T": "Селища міського типу",
|
|
29
|
+
"C": "Села",
|
|
30
|
+
"X": "Селища",
|
|
31
|
+
"B": "Райони в містах",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
df["Назва категорії об’єкта"] = df["Категорія об’єкта"].map(
|
|
35
|
+
category_mapping
|
|
36
|
+
)
|
|
37
|
+
return df
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class KatottgEntity:
|
|
2
|
+
def __init__(self, entity_id, name, category, parent=None):
|
|
3
|
+
self.entity_id = entity_id
|
|
4
|
+
self.name = name
|
|
5
|
+
self.category = category
|
|
6
|
+
self.parent = parent
|
|
7
|
+
|
|
8
|
+
def add_parent(self, parent):
|
|
9
|
+
if self.parent is None:
|
|
10
|
+
self.parent = parent
|
|
11
|
+
else:
|
|
12
|
+
self.parent.add_parent(parent)
|
|
13
|
+
|
|
14
|
+
def __str__(self, indent=""):
|
|
15
|
+
output = f"{indent}{self.category} - {self.name} [{self.entity_id}]"
|
|
16
|
+
if self.parent:
|
|
17
|
+
output += "\n" + self.parent.__str__(indent + "\t")
|
|
18
|
+
return output
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: katottglib
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python lib to operate KATOTTG addresses (classified administrative division of Ukraine).
|
|
5
|
+
Home-page: https://github.com/sen-den/katottglib
|
|
6
|
+
Author: Denis Senchishen
|
|
7
|
+
Author-email: dsenchishen@icloud.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Description-Content-Type: text/x-rst
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
|
|
17
|
+
===========
|
|
18
|
+
KATOTTG lib
|
|
19
|
+
===========
|
|
20
|
+
|
|
21
|
+
Quick start
|
|
22
|
+
-----------
|
|
23
|
+
|
|
24
|
+
To be done...
|
|
25
|
+
|
|
26
|
+
Release notes
|
|
27
|
+
-------------
|
|
28
|
+
|
|
29
|
+
v0.1.0 (2023-06-10)
|
|
30
|
+
...................
|
|
31
|
+
|
|
32
|
+
Initial release.
|
|
33
|
+
|
|
34
|
+
- Search by name with filter by level (``find_by_name``).
|
|
35
|
+
- Search by identifier (``find_by_id``)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.rst
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.cfg
|
|
5
|
+
setup.py
|
|
6
|
+
data/__init__.py
|
|
7
|
+
data/data.py
|
|
8
|
+
data/entity.py
|
|
9
|
+
katottglib.egg-info/PKG-INFO
|
|
10
|
+
katottglib.egg-info/SOURCES.txt
|
|
11
|
+
katottglib.egg-info/dependency_links.txt
|
|
12
|
+
katottglib.egg-info/top_level.txt
|
|
13
|
+
test/__init__.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[tool.black]
|
|
2
|
+
line-length = 80
|
|
3
|
+
multi_line_output = 3
|
|
4
|
+
include-trailing-comma = true
|
|
5
|
+
target-version = ['py311']
|
|
6
|
+
extend-exclude = '''
|
|
7
|
+
/(
|
|
8
|
+
\.git
|
|
9
|
+
| \.github
|
|
10
|
+
| \.idea
|
|
11
|
+
| \.venv
|
|
12
|
+
)/
|
|
13
|
+
'''
|
|
14
|
+
|
|
15
|
+
[tool.isort]
|
|
16
|
+
profile = "black"
|
|
17
|
+
line_length = 80
|
|
18
|
+
force_sort_within_sections = true
|
|
19
|
+
atomic = true
|
|
20
|
+
|
|
21
|
+
[tool.mypy]
|
|
22
|
+
python_version = "3.11"
|
|
23
|
+
show_error_codes = true
|
|
24
|
+
warn_return_any = false
|
|
25
|
+
pretty = true
|
|
26
|
+
follow_imports = 'silent'
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[metadata]
|
|
2
|
+
name = katottglib
|
|
3
|
+
version = 0.1.0
|
|
4
|
+
description = A Python lib to operate KATOTTG addresses (classified administrative division of Ukraine).
|
|
5
|
+
long_description = file: README.rst
|
|
6
|
+
long_description_content_type = text/x-rst
|
|
7
|
+
url = https://github.com/sen-den/katottglib
|
|
8
|
+
author = Denis Senchishen
|
|
9
|
+
author_email = dsenchishen@icloud.com
|
|
10
|
+
license = MIT
|
|
11
|
+
classifiers =
|
|
12
|
+
Intended Audience :: Developers
|
|
13
|
+
License :: OSI Approved :: MIT License
|
|
14
|
+
Operating System :: OS Independent
|
|
15
|
+
Programming Language :: Python
|
|
16
|
+
Programming Language :: Python :: 3
|
|
17
|
+
|
|
18
|
+
[options]
|
|
19
|
+
include_package_data = true
|
|
20
|
+
packages = find:
|
|
21
|
+
|
|
22
|
+
[egg_info]
|
|
23
|
+
tag_build =
|
|
24
|
+
tag_date = 0
|
|
25
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
import katottg
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class KatottgSearchTestCase(unittest.TestCase):
|
|
7
|
+
def test_simple_search(self):
|
|
8
|
+
cases = (
|
|
9
|
+
("Херсон", "UA65100150010064384"),
|
|
10
|
+
("Миколаїв", "UA46100110010094231"),
|
|
11
|
+
("Миколаївка", "UA05100090120011921"),
|
|
12
|
+
("Червона Поляна", "UA05100110150052879"),
|
|
13
|
+
)
|
|
14
|
+
for input_query, expected_id in cases:
|
|
15
|
+
actual = katottg.find_by_name(input_query)
|
|
16
|
+
self.assertTrue(len(actual) > 0)
|
|
17
|
+
self.assertEqual(expected_id, actual[0].entity_id)
|
|
18
|
+
|
|
19
|
+
def test_search_in_parent(self):
|
|
20
|
+
cases = (
|
|
21
|
+
("Червона Поляна", "UA65000000000030969", "UA65060130090033121"), # В Херсонській області
|
|
22
|
+
("Червона Поляна", "UA35000000000016081", "UA35060090140077182"), # В Кіровоградській області
|
|
23
|
+
)
|
|
24
|
+
for input_query, parent_id, expected_id in cases:
|
|
25
|
+
actual = katottg.find_by_name(input_query, parent_id=parent_id)
|
|
26
|
+
self.assertTrue(len(actual) > 0)
|
|
27
|
+
self.assertEqual(expected_id, actual[0].entity_id)
|
|
28
|
+
|
|
29
|
+
def test_search_with_limit(self):
|
|
30
|
+
self.assertEqual(len(katottg.find_by_name("Червона Поляна")), 5)
|
|
31
|
+
self.assertEqual(len(katottg.find_by_name("Червона Поляна", limit=5)), 5)
|
|
32
|
+
self.assertEqual(len(katottg.find_by_name("Червона Поляна", limit=100)), 100) # No similarity threshold yet!
|
|
33
|
+
|
|
34
|
+
def test_find_by_id(self):
|
|
35
|
+
self.assertEqual(katottg.find_by_id("UA65060130090033121").name, "Червона Поляна")
|
|
36
|
+
self.assertEqual(katottg.find_by_id("UA65100150010064384").name, "Херсон")
|
|
37
|
+
self.assertEqual(katottg.find_by_id("UA00000001234567890"), None)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == '__main__':
|
|
41
|
+
unittest.main()
|