poland-py 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.
- poland_py-0.1.0/PKG-INFO +18 -0
- poland_py-0.1.0/README.md +8 -0
- poland_py-0.1.0/poland/__init__.py +0 -0
- poland_py-0.1.0/poland/pesel.py +96 -0
- poland_py-0.1.0/poland_py.egg-info/PKG-INFO +18 -0
- poland_py-0.1.0/poland_py.egg-info/SOURCES.txt +8 -0
- poland_py-0.1.0/poland_py.egg-info/dependency_links.txt +1 -0
- poland_py-0.1.0/poland_py.egg-info/top_level.txt +1 -0
- poland_py-0.1.0/pyproject.toml +19 -0
- poland_py-0.1.0/setup.cfg +4 -0
poland_py-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: poland-py
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight Python utility for Polish data formats, PESEL parsing, and validation.
|
|
5
|
+
Author-email: Rylse Solutions <hello@rylse.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: poland,pesel,validator,parser,utilities
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# 🇵🇱 poland
|
|
12
|
+
|
|
13
|
+
A lightweight, zero-dependency Python utility for validating and extracting metadata from Polish identifiers (PESEL, and more).
|
|
14
|
+
|
|
15
|
+
## âš¡ Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install poland
|
|
File without changes
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from datetime import date, datetime
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
class PESEL:
|
|
5
|
+
WEIGHTS = (1, 3, 7, 9, 1, 3, 7, 9, 1, 3)
|
|
6
|
+
|
|
7
|
+
def __init__(self, raw_value: str):
|
|
8
|
+
self.raw = str(raw_value).strip()
|
|
9
|
+
self._is_valid: Optional[bool] = None
|
|
10
|
+
self._birth_date: Optional[date] = None
|
|
11
|
+
self._gender: Optional[str] = None
|
|
12
|
+
self._parse()
|
|
13
|
+
|
|
14
|
+
def _parse(self) -> None:
|
|
15
|
+
if not self.raw.isdigit() or len(self.raw) != 11:
|
|
16
|
+
self._is_valid = False
|
|
17
|
+
return
|
|
18
|
+
|
|
19
|
+
digits = [int(d) for d in self.raw]
|
|
20
|
+
|
|
21
|
+
# 1. Suma kontrolna
|
|
22
|
+
checksum = sum(w * d for w, d in zip(self.WEIGHTS, digits[:10]))
|
|
23
|
+
control_digit = (10 - (checksum % 10)) % 10
|
|
24
|
+
|
|
25
|
+
if control_digit != digits[10]:
|
|
26
|
+
self._is_valid = False
|
|
27
|
+
return
|
|
28
|
+
|
|
29
|
+
# 2. Dekodowanie stulecia i daty urodzenia
|
|
30
|
+
year_part = digits[0] * 10 + digits[1]
|
|
31
|
+
month_part = digits[2] * 10 + digits[3]
|
|
32
|
+
day = digits[4] * 10 + digits[5]
|
|
33
|
+
|
|
34
|
+
if 1 <= month_part <= 12:
|
|
35
|
+
year = 1900 + year_part
|
|
36
|
+
month = month_part
|
|
37
|
+
elif 21 <= month_part <= 32:
|
|
38
|
+
year = 2000 + year_part
|
|
39
|
+
month = month_part - 20
|
|
40
|
+
elif 41 <= month_part <= 52:
|
|
41
|
+
year = 2100 + year_part
|
|
42
|
+
month = month_part - 40
|
|
43
|
+
elif 61 <= month_part <= 72:
|
|
44
|
+
year = 2200 + year_part
|
|
45
|
+
month = month_part - 60
|
|
46
|
+
elif 81 <= month_part <= 92:
|
|
47
|
+
year = 1800 + year_part
|
|
48
|
+
month = month_part - 80
|
|
49
|
+
else:
|
|
50
|
+
self._is_valid = False
|
|
51
|
+
return
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
self._birth_date = date(year, month, day)
|
|
55
|
+
except ValueError:
|
|
56
|
+
self._is_valid = False
|
|
57
|
+
return
|
|
58
|
+
|
|
59
|
+
# 3. Płeć (10. cyfra: parzysta = kobieta, nieparzysta = mężczyzna)
|
|
60
|
+
self._gender = "female" if digits[9] % 2 == 0 else "male"
|
|
61
|
+
self._is_valid = True
|
|
62
|
+
|
|
63
|
+
def is_valid(self) -> bool:
|
|
64
|
+
return bool(self._is_valid)
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def birth_date(self) -> Optional[date]:
|
|
68
|
+
return self._birth_date if self.is_valid() else None
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def year(self) -> Optional[int]:
|
|
72
|
+
return self._birth_date.year if self._birth_date else None
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def month(self) -> Optional[int]:
|
|
76
|
+
return self._birth_date.month if self._birth_date else None
|
|
77
|
+
|
|
78
|
+
@property
|
|
79
|
+
def day(self) -> Optional[int]:
|
|
80
|
+
return self._birth_date.day if self._birth_date else None
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def gender(self) -> Optional[str]:
|
|
84
|
+
return self._gender if self.is_valid() else None
|
|
85
|
+
|
|
86
|
+
@property
|
|
87
|
+
def age(self) -> Optional[int]:
|
|
88
|
+
if not self._birth_date:
|
|
89
|
+
return None
|
|
90
|
+
today = date.today()
|
|
91
|
+
return today.year - self._birth_date.year - (
|
|
92
|
+
(today.month, today.day) < (self._birth_date.month, self._birth_date.day)
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
def __repr__(self) -> str:
|
|
96
|
+
return f"<PESEL raw='{self.raw}' valid={self.is_valid()}>"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: poland-py
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight Python utility for Polish data formats, PESEL parsing, and validation.
|
|
5
|
+
Author-email: Rylse Solutions <hello@rylse.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: poland,pesel,validator,parser,utilities
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# 🇵🇱 poland
|
|
12
|
+
|
|
13
|
+
A lightweight, zero-dependency Python utility for validating and extracting metadata from Polish identifiers (PESEL, and more).
|
|
14
|
+
|
|
15
|
+
## âš¡ Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install poland
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
poland
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "poland-py"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Lightweight Python utility for Polish data formats, PESEL parsing, and validation."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Rylse Solutions", email = "hello@rylse.com" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["poland", "pesel", "validator", "parser", "utilities"]
|
|
16
|
+
|
|
17
|
+
[tool.setuptools.packages.find]
|
|
18
|
+
where = ["."]
|
|
19
|
+
include = ["poland*"]
|