diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a5628f4..32a73d7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.9.0 + rev: v3.10.1 hooks: - id: pyupgrade args: ["--py38-plus"] @@ -14,7 +14,7 @@ repos: - id: fix-future-annotations - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.278 + rev: v0.0.287 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/README.md b/README.md index e354728..9d46b83 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![](https://img.shields.io/pypi/pyversions/python-codicefiscale.svg?logoColor=white&color=blue&logo=python)](https://www.python.org/) [![](https://img.shields.io/pypi/v/python-codicefiscale.svg?color=blue&logo=pypi&logoColor=white)](https://pypi.org/project/python-codicefiscale/) -[![](https://pepy.tech/badge/python-codicefiscale/month)](https://pepy.tech/project/python-codicefiscale) +[![](https://static.pepy.tech/badge/python-codicefiscale/month)](https://pepy.tech/project/python-codicefiscale) [![](https://img.shields.io/github/stars/fabiocaccamo/python-codicefiscale?logo=github)](https://github.com/fabiocaccamo/python-codicefiscale/stargazers) [![](https://img.shields.io/pypi/l/python-codicefiscale.svg?color=blue&)](https://github.com/fabiocaccamo/python-codicefiscale/blob/main/LICENSE) diff --git a/codicefiscale/data/countries-patch.json b/codicefiscale/data/countries-patch.json new file mode 100644 index 0000000..32960f8 --- /dev/null +++ b/codicefiscale/data/countries-patch.json @@ -0,0 +1,2 @@ +[ +] \ No newline at end of file diff --git a/codicefiscale/data/municipalities-patch.json b/codicefiscale/data/municipalities-patch.json new file mode 100644 index 0000000..6b41cee --- /dev/null +++ b/codicefiscale/data/municipalities-patch.json @@ -0,0 +1,44 @@ +[ + { + "active": false, + "code": "F383", + "date_created": "1928-05-12T00:00:00", + "date_deleted": "1991-12-09T00:00:00", + "name": "Monserrato", + "name_alt": "", + "name_alt_trans": "", + "name_slugs": [ + "monserrato" + ], + "name_trans": "Monserrato", + "province": "CA" + }, + { + "active": false, + "code": "G133", + "date_created": "1928-11-28T00:00:00", + "date_deleted": "1948-04-07T00:00:00", + "name": "Ortacesus", + "name_alt": "", + "name_alt_trans": "", + "name_slugs": [ + "ortacesus" + ], + "name_trans": "Ortacesus", + "province": "CA" + }, + { + "active": false, + "code": "L513", + "date_created": "1927-11-04T00:00:00", + "date_deleted": "1946-02-27T00:00:00", + "name": "Ussaramanna", + "name_alt": "", + "name_alt_trans": "", + "name_slugs": [ + "ussaramanna" + ], + "name_trans": "Ussaramanna", + "province": "CA" + } +] \ No newline at end of file diff --git a/codicefiscale/data/municipalities.json b/codicefiscale/data/municipalities.json index ccdb43e..c6bcb56 100644 --- a/codicefiscale/data/municipalities.json +++ b/codicefiscale/data/municipalities.json @@ -139084,6 +139084,20 @@ "name_trans": "Monserrato", "province": "CA" }, + { + "active": false, + "code": "F383", + "date_created": "1928-05-12T00:00:00", + "date_deleted": "1991-12-09T00:00:00", + "name": "Monserrato", + "name_alt": "", + "name_alt_trans": "", + "name_slugs": [ + "monserrato" + ], + "name_trans": "Monserrato", + "province": "CA" + }, { "active": false, "code": "F384", @@ -158555,6 +158569,20 @@ "name_trans": "Ortacesus", "province": "SU" }, + { + "active": false, + "code": "G133", + "date_created": "1928-11-28T00:00:00", + "date_deleted": "1948-04-07T00:00:00", + "name": "Ortacesus", + "name_alt": "", + "name_alt_trans": "", + "name_slugs": [ + "ortacesus" + ], + "name_trans": "Ortacesus", + "province": "CA" + }, { "active": false, "code": "G135", @@ -251715,6 +251743,20 @@ "name_trans": "Ussaramanna", "province": "SU" }, + { + "active": false, + "code": "L513", + "date_created": "1927-11-04T00:00:00", + "date_deleted": "1946-02-27T00:00:00", + "name": "Ussaramanna", + "name_alt": "", + "name_alt_trans": "", + "name_slugs": [ + "ussaramanna" + ], + "name_trans": "Ussaramanna", + "province": "CA" + }, { "active": false, "code": "L514", diff --git a/requirements-test.txt b/requirements-test.txt index 386111b..801d1f3 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,4 +1,4 @@ -coverage == 7.2.* +coverage == 7.3.* mypy == 1.5.* pre-commit == 3.3.* -tox == 4.6.* +tox == 4.11.* diff --git a/scripts/updatedata.py b/scripts/updatedata.py index aa67710..478590e 100644 --- a/scripts/updatedata.py +++ b/scripts/updatedata.py @@ -2,6 +2,8 @@ from benedict import benedict from slugify import slugify +DATA_DIR = fsutil.join_path(__file__, "../codicefiscale/data/") + def _expect_keys(d, keys): missing_keys = list(set(keys) - set(d.keys())) @@ -71,9 +73,12 @@ def map_item(item): "province": province, } + items_data = [map_item(benedict(item)) for item in data["values"]] + items_data_patch = _read_data_json("countries-patch.json") + _write_data_json( - filepath="../codicefiscale/data/countries.json", - data=[map_item(benedict(item)) for item in data["values"]], + filepath="countries.json", + data=items_data + items_data_patch, ) @@ -142,17 +147,31 @@ def map_item(item): "province": province, } + items_data = [map_item(benedict(item)) for item in data["values"]] + items_data_patch = _read_data_json("municipalities-patch.json") + _write_data_json( - filepath="../codicefiscale/data/municipalities.json", - data=[map_item(benedict(item)) for item in data["values"]], + filepath="municipalities.json", + data=items_data + items_data_patch, ) +def _read_data_json(filepath): + data = fsutil.read_file_json( + fsutil.join_filepath(DATA_DIR, filepath), + ) + return data + + def _write_data_json(filepath, data): data = list(filter(bool, data)) data = sorted(data, key=lambda item: item["name"]) - data_filepath = fsutil.join_path(__file__, filepath) - fsutil.write_file_json(data_filepath, data, indent=4, sort_keys=True) + fsutil.write_file_json( + fsutil.join_filepath(DATA_DIR, filepath), + data, + indent=4, + sort_keys=True, + ) def main(): diff --git a/tests/test_issue_0113.py b/tests/test_issue_0113.py new file mode 100644 index 0000000..5ffb31a --- /dev/null +++ b/tests/test_issue_0113.py @@ -0,0 +1,32 @@ +import datetime +import unittest + +from codicefiscale import codicefiscale + + +class Issue0113TestCase(unittest.TestCase): + def test_issue_0113(self): + """ + Wrong birthplace code error (missing date-range in the data-source). + """ + codes = [ + "XXXXXX39D44G133O", + "XXXXXX46D11F383M", + "XXXXXX50H18F383N", + "XXXXXX38C71L513V", + "XXXXXX43C14G133F", + ] + expected_birthdates = [ + datetime.datetime(1939, 4, 4, 0, 0), + datetime.datetime(1946, 4, 11, 0, 0), + datetime.datetime(1950, 6, 18, 0, 0), + datetime.datetime(1938, 3, 31, 0, 0), + datetime.datetime(1943, 3, 14, 0, 0), + ] + for index, code in enumerate(codes): + with self.subTest(f"code: {code}"): + code_data = codicefiscale.decode(code) + code_data.pop("omocodes") + code_data.pop("raw") + # print(code_data) + self.assertEqual(code_data["birthdate"], expected_birthdates[index])