nepal-sub-divisions 0.0.1__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Dinesh Kumar Roy
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,3 @@
1
+ include README.md
2
+ include src/data/data.*json
3
+ include src/nepali_municipalities
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.1
2
+ Name: nepal-sub-divisions
3
+ Version: 0.0.1
4
+ Summary: Nepali municipalities is a python package to get data about Nepali municipalities based on districts
5
+ Home-page: https://github.com/iDineshRoy/nepal-sub-divisions
6
+ Author: Dinesh Roy
7
+ Author-email: dinesh.roy@hotmail.com
8
+ Keywords: Nepali,nepal,nepal provinces,nepali districts,nepali municipalities,dinesh roy,nepali states
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+
16
+ # Nepali Municipalities
17
+ [![Downloads](https://static.pepy.tech/personalized-badge/nepal-sub-divisions?period=total&units=international_system&left_color=black&right_color=yellowgreen&left_text=Downloads)](https://pepy.tech/project/nepal-sub-divisions)
18
+
19
+
20
+ This is a simple and small python package contributed by me to get all list of municipalities of Nepal based on given districts of Nepal on latest version now you can autocomplete other info when municipalities name is given.
21
+
22
+ # Contents
23
+ Installation
24
+ Use the package manager pip to install nepal-sub-divisions.
25
+
26
+
27
+ To Autocomplete all info based on municipalities name provided
28
+ for example if you provide municipalities names then rest of district and province will be autocompleted.
29
+
30
+ ```python
31
+ from nepal_municipalities import NepalMunicipality
32
+
33
+ print(NepalMunicipality.all_data_info('Kathmandu'))
34
+ [{'province': 'Province 3', 'country': 'Nepal', 'id': 311, 'district': 'Kathmandu', 'name': 'Kathmandu'}]
35
+ ```
36
+
37
+ **If No matching municipalities are supplied The Exception is thrown as below**
38
+ ``` python
39
+ No matching info for provided municipalities try changing spelling or try another name.
40
+ ```
41
+
42
+
43
+
44
+ **To get list of all districts of Nepal**
45
+
46
+ ```python
47
+ from nepali_municipalities import NepalMunicipality
48
+
49
+ print(NepalMunicipality.all_districts()) # this will also give the same result
50
+ # ['Bhojpur', 'Dhankuta', 'Ilam', 'Jhapa', ......]
51
+
52
+ print(NepalMunicipality.all_districts("Koshi")) # search by province name
53
+ # ['Morang', 'Sankhuwasabha', 'Udayapur', 'Jhapa', ......]
54
+
55
+ ```
56
+
57
+ To get list of all municipalities of Nepal based on District provided.
58
+
59
+ ```python
60
+ from nepali_municipalities import NepalMunicipality
61
+
62
+ print(NepalMunicipality.municipalities('Kathmandu'))
63
+
64
+ # ['Kathmandu', 'Kageshwori Manohara', 'Kirtipur', 'Gokarneshwor', 'Chandragiri', 'Tokha', 'Tarkeshwor', 'Dakchinkali', 'Nagarjun', 'Budhanilkantha', 'Shankharapur']
65
+
66
+ ```
67
+
68
+
69
+ # Contributing
70
+ PRs are welcomed. Please, let me know if you have any suggestions or find any bugs.
71
+
72
+
73
+ ## License
74
+ [MIT](https://choosealicense.com/licenses/mit/)
@@ -0,0 +1,59 @@
1
+ # Nepali Municipalities
2
+ [![Downloads](https://static.pepy.tech/personalized-badge/nepal-sub-divisions?period=total&units=international_system&left_color=black&right_color=yellowgreen&left_text=Downloads)](https://pepy.tech/project/nepal-sub-divisions)
3
+
4
+
5
+ This is a simple and small python package contributed by me to get all list of municipalities of Nepal based on given districts of Nepal on latest version now you can autocomplete other info when municipalities name is given.
6
+
7
+ # Contents
8
+ Installation
9
+ Use the package manager pip to install nepal-sub-divisions.
10
+
11
+
12
+ To Autocomplete all info based on municipalities name provided
13
+ for example if you provide municipalities names then rest of district and province will be autocompleted.
14
+
15
+ ```python
16
+ from nepal_municipalities import NepalMunicipality
17
+
18
+ print(NepalMunicipality.all_data_info('Kathmandu'))
19
+ [{'province': 'Province 3', 'country': 'Nepal', 'id': 311, 'district': 'Kathmandu', 'name': 'Kathmandu'}]
20
+ ```
21
+
22
+ **If No matching municipalities are supplied The Exception is thrown as below**
23
+ ``` python
24
+ No matching info for provided municipalities try changing spelling or try another name.
25
+ ```
26
+
27
+
28
+
29
+ **To get list of all districts of Nepal**
30
+
31
+ ```python
32
+ from nepali_municipalities import NepalMunicipality
33
+
34
+ print(NepalMunicipality.all_districts()) # this will also give the same result
35
+ # ['Bhojpur', 'Dhankuta', 'Ilam', 'Jhapa', ......]
36
+
37
+ print(NepalMunicipality.all_districts("Koshi")) # search by province name
38
+ # ['Morang', 'Sankhuwasabha', 'Udayapur', 'Jhapa', ......]
39
+
40
+ ```
41
+
42
+ To get list of all municipalities of Nepal based on District provided.
43
+
44
+ ```python
45
+ from nepali_municipalities import NepalMunicipality
46
+
47
+ print(NepalMunicipality.municipalities('Kathmandu'))
48
+
49
+ # ['Kathmandu', 'Kageshwori Manohara', 'Kirtipur', 'Gokarneshwor', 'Chandragiri', 'Tokha', 'Tarkeshwor', 'Dakchinkali', 'Nagarjun', 'Budhanilkantha', 'Shankharapur']
50
+
51
+ ```
52
+
53
+
54
+ # Contributing
55
+ PRs are welcomed. Please, let me know if you have any suggestions or find any bugs.
56
+
57
+
58
+ ## License
59
+ [MIT](https://choosealicense.com/licenses/mit/)
@@ -0,0 +1 @@
1
+ from .nepali_municipalities import *
@@ -0,0 +1,141 @@
1
+ import json
2
+ import os
3
+ from typing import Dict
4
+
5
+
6
+ class DistrictNotFoundException(Exception):
7
+ """Exception to be raised if correct district is not provided by user"""
8
+
9
+ pass
10
+
11
+
12
+ class DistrictNotProvidedException(Exception):
13
+ """Exception to be raised if district is not provided by user"""
14
+
15
+ pass
16
+
17
+
18
+ class MunicipalityNotFoundException(Exception):
19
+ """Exception to be raised if municipality is not found"""
20
+
21
+ pass
22
+
23
+
24
+ class NepalMunicipality:
25
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
26
+ DATA_PATH = os.path.join(BASE_DIR, "data", "data.json")
27
+ ALL_MUNICIPALITIES_PATH = os.path.join(
28
+ BASE_DIR, "data", "all_nepali_municipalities.json"
29
+ )
30
+
31
+ def __init__(self, district_name: str = None):
32
+ self.municipality_name = None
33
+ self._district_name = district_name
34
+ self._data = self._load_json(self.DATA_PATH)
35
+
36
+ @staticmethod
37
+ def _load_json(file_path: str) -> list[Dict]:
38
+ with open(file_path, "r") as f:
39
+ return json.load(f)
40
+
41
+ def all_municipalities(self):
42
+ """
43
+ Use this to get list of all municipalities of specific district
44
+ provided from class instance if district is none You will get None as return Value
45
+ """
46
+ if self._district_name is not None:
47
+ for items in self._data:
48
+ if self._district_name in self.all_districts():
49
+ if items.get(self._district_name) is not None:
50
+ return items.get(self._district_name)
51
+ else:
52
+ raise DistrictNotFoundException(
53
+ "District not found for following text, please check "
54
+ "district spelling."
55
+ )
56
+ raise DistrictNotProvidedException(
57
+ "District not provided please provide district name."
58
+ )
59
+
60
+ @classmethod
61
+ def municipalities(cls, district_name: str = None):
62
+ """
63
+ Use this method to get a list of all municipalities in a specific district.
64
+ :param district_name: The name of the district. If None, use the instance's district name.
65
+ :return: A list of municipalities in the specified district.
66
+ """
67
+ # Check if this is an instance method call
68
+ if not isinstance(cls, type):
69
+ # This is an instance method call
70
+ district_name = district_name or cls._district_name
71
+
72
+ # If district_name is still None, raise the exception
73
+ if district_name is None:
74
+ raise DistrictNotProvidedException(
75
+ "District not provided. Please provide a district name."
76
+ )
77
+
78
+ data = cls._load_json(cls.DATA_PATH)
79
+ districts = cls.all_districts()
80
+
81
+ if district_name not in districts:
82
+ raise DistrictNotFoundException(
83
+ f"District '{district_name}' not found. Please check the spelling."
84
+ )
85
+
86
+ for item in data:
87
+ if district_name in item:
88
+ return item[district_name]
89
+
90
+ raise DistrictNotFoundException(
91
+ f"Municipalities for district '{district_name}' could not be found."
92
+ )
93
+
94
+ @classmethod
95
+ def all_districts(cls, province_name: str = None) -> list[str]:
96
+ """Use this method to get a list of all districts of Nepal."""
97
+ data = cls._load_json(cls.DATA_PATH)
98
+ muni_data = cls._load_json(cls.ALL_MUNICIPALITIES_PATH)
99
+ all_districts: list = [list(item.keys())[0] for item in data]
100
+ if province_name:
101
+ filtered_entries = [e for e in muni_data if e["province"] == province_name]
102
+ all_districts = list(set([entry["district"] for entry in filtered_entries]))
103
+ return all_districts
104
+
105
+ @classmethod
106
+ def all_data_info(cls, municipality_name: str = None) -> Dict[str, str]:
107
+ """
108
+ Use this method to get the details of a specific municipality, such as its district, province, and province number.
109
+ :param municipality_name: The name of the municipality.
110
+ :return: A dictionary with details about the municipality.
111
+ """
112
+ data = cls._load_json(cls.ALL_MUNICIPALITIES_PATH)
113
+
114
+ province_mapping = {
115
+ "Koshi": "Province 1",
116
+ "Madhesh": "Province 2",
117
+ "Bagmati": "Province 3",
118
+ "Gandaki": "Province 4",
119
+ "Lumbini": "Province 5",
120
+ "Karnali": "Province 6",
121
+ "Sudurpashchim": "Province 7",
122
+ }
123
+
124
+ for item in data:
125
+ if item["name"].lower() == municipality_name.lower():
126
+ return {
127
+ "municipality": item["name"],
128
+ "district": item["district"],
129
+ "province": item["province"],
130
+ "province_no": province_mapping.get(item["province"], "Unknown"),
131
+ "country": item["country"],
132
+ }
133
+
134
+ raise MunicipalityNotFoundException(
135
+ f"No matching info for provided municipality '{municipality_name}'. "
136
+ "Please check the spelling or try another name."
137
+ )
138
+
139
+
140
+ if __name__ == "__main__":
141
+ print(NepalMunicipality.all_data_info("Kathmandu"))
@@ -0,0 +1,4 @@
1
+ from nepal_municipalities import NepalMunicipality
2
+
3
+ district = NepalMunicipality.all_municipalities("Kaski")
4
+ print(district)
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.1
2
+ Name: nepal-sub-divisions
3
+ Version: 0.0.1
4
+ Summary: Nepali municipalities is a python package to get data about Nepali municipalities based on districts
5
+ Home-page: https://github.com/iDineshRoy/nepal-sub-divisions
6
+ Author: Dinesh Roy
7
+ Author-email: dinesh.roy@hotmail.com
8
+ Keywords: Nepali,nepal,nepal provinces,nepali districts,nepali municipalities,dinesh roy,nepali states
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+
16
+ # Nepali Municipalities
17
+ [![Downloads](https://static.pepy.tech/personalized-badge/nepal-sub-divisions?period=total&units=international_system&left_color=black&right_color=yellowgreen&left_text=Downloads)](https://pepy.tech/project/nepal-sub-divisions)
18
+
19
+
20
+ This is a simple and small python package contributed by me to get all list of municipalities of Nepal based on given districts of Nepal on latest version now you can autocomplete other info when municipalities name is given.
21
+
22
+ # Contents
23
+ Installation
24
+ Use the package manager pip to install nepal-sub-divisions.
25
+
26
+
27
+ To Autocomplete all info based on municipalities name provided
28
+ for example if you provide municipalities names then rest of district and province will be autocompleted.
29
+
30
+ ```python
31
+ from nepal_municipalities import NepalMunicipality
32
+
33
+ print(NepalMunicipality.all_data_info('Kathmandu'))
34
+ [{'province': 'Province 3', 'country': 'Nepal', 'id': 311, 'district': 'Kathmandu', 'name': 'Kathmandu'}]
35
+ ```
36
+
37
+ **If No matching municipalities are supplied The Exception is thrown as below**
38
+ ``` python
39
+ No matching info for provided municipalities try changing spelling or try another name.
40
+ ```
41
+
42
+
43
+
44
+ **To get list of all districts of Nepal**
45
+
46
+ ```python
47
+ from nepali_municipalities import NepalMunicipality
48
+
49
+ print(NepalMunicipality.all_districts()) # this will also give the same result
50
+ # ['Bhojpur', 'Dhankuta', 'Ilam', 'Jhapa', ......]
51
+
52
+ print(NepalMunicipality.all_districts("Koshi")) # search by province name
53
+ # ['Morang', 'Sankhuwasabha', 'Udayapur', 'Jhapa', ......]
54
+
55
+ ```
56
+
57
+ To get list of all municipalities of Nepal based on District provided.
58
+
59
+ ```python
60
+ from nepali_municipalities import NepalMunicipality
61
+
62
+ print(NepalMunicipality.municipalities('Kathmandu'))
63
+
64
+ # ['Kathmandu', 'Kageshwori Manohara', 'Kirtipur', 'Gokarneshwor', 'Chandragiri', 'Tokha', 'Tarkeshwor', 'Dakchinkali', 'Nagarjun', 'Budhanilkantha', 'Shankharapur']
65
+
66
+ ```
67
+
68
+
69
+ # Contributing
70
+ PRs are welcomed. Please, let me know if you have any suggestions or find any bugs.
71
+
72
+
73
+ ## License
74
+ [MIT](https://choosealicense.com/licenses/mit/)
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ setup.py
5
+ nepal_municipalities/__init__.py
6
+ nepal_municipalities/nepal_municipalities.py
7
+ nepal_municipalities/test.py
8
+ nepal_municipalities/data/__init__.py
9
+ nepal_sub_divisions.egg-info/PKG-INFO
10
+ nepal_sub_divisions.egg-info/SOURCES.txt
11
+ nepal_sub_divisions.egg-info/dependency_links.txt
12
+ nepal_sub_divisions.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ nepal_municipalities
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,33 @@
1
+ import setuptools as setuptools
2
+ from setuptools import setup
3
+
4
+ with open("README.md", "r") as fh:
5
+ long_description = fh.read()
6
+
7
+ setup(
8
+ name="nepal-sub-divisions",
9
+ version="0.0.1", # Required
10
+ description="Nepali municipalities is a python package to get data about Nepali municipalities based on districts",
11
+ url="https://github.com/iDineshRoy/nepal-sub-divisions",
12
+ long_description=long_description,
13
+ long_description_content_type="text/markdown",
14
+ author="Dinesh Roy",
15
+ author_email="dinesh.roy@hotmail.com",
16
+ packages=setuptools.find_packages(),
17
+ classifiers=[
18
+ "Programming Language :: Python :: 3",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Operating System :: OS Independent",
21
+ ],
22
+ python_requires=">=3.6",
23
+ include_package_data=True,
24
+ keywords=[
25
+ "Nepali",
26
+ "nepal",
27
+ "nepal provinces",
28
+ "nepali districts",
29
+ "nepali municipalities",
30
+ "dinesh roy",
31
+ "nepali states",
32
+ ],
33
+ )