Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/311 validation country code #317

Merged
merged 1 commit into from
Jan 30, 2025

Conversation

danielmursa-dev
Copy link
Contributor

Fixes #311

  • Updated all land fields
  • Added validate_country
  • Created migrations, with nl_code_to_iso_code_country_converter (ISO 3166)

Created COUNTRIES_DICT in openklant/utils/constants.py, from https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://publicaties.rvig.nl/dsresource%3Fobjectid%3D7a15a0d7-7282-403c-92a8-397f0da23d44%26type%3Dpdf&ved=2ahUKEwiK6Z6ymeiKAxUT2AIHHXInHC8QFnoECBoQAQ&usg=AOvVaw1Y5bNvX9xsQjY0ihbxKPfJ

COUNTRIES_DICT = {
    "CA": {
        "nl_code": "5001",
        "iso_code": "CA",
        "name": "Canada",
    },
    "FR": {
        "nl_code": "5002",
        "iso_code": "FR",
        "name": "Frankrijk",
    },
    ....
}

Script:

from PyPDF2 import PdfReader

countries = {}
empty_data = {"nl_code": "", "iso_code": "", "name": ""}
reader = PdfReader("Tabel 34 Landen (gesorteerd op code).pdf")

for page in reader.pages:
    current_data = empty_data.copy()
    for line in page.extract_text().splitlines():
        line = line.strip()

        if len(line) == 4 and line.isdigit():
            current_data["nl_code"] = line
            continue

        if current_data["nl_code"] and len(line) == 2:
            current_data["iso_code"] = line
            continue

        if current_data["nl_code"] and current_data["iso_code"]:
            iso_code = current_data["iso_code"]
            current_data["name"] = line
            countries[iso_code] = current_data
            current_data = empty_data.copy()
            continue

print(countries)
print(len(countries))

Copy link
Contributor

@Coperh Coperh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good I think, so this is a soft approve

I think you should test bad and empty country codes in the migration, just to make sure all cases are covered.

Copy link
Collaborator

@stevenbal stevenbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly small stuff, looks good otherwise.

Once it is approved, could you rebase or squash the commits?

@danielmursa-dev danielmursa-dev force-pushed the feature/311-validation-country-code branch 2 times, most recently from 6b6a99a to e92eae5 Compare January 30, 2025 10:14
[#311] Update models + migrations

[#311] Create Tests

Schema
@danielmursa-dev danielmursa-dev force-pushed the feature/311-validation-country-code branch from e92eae5 to 5639fa0 Compare January 30, 2025 10:16
@stevenbal stevenbal merged commit c7ffa69 into master Jan 30, 2025
28 checks passed
@stevenbal stevenbal deleted the feature/311-validation-country-code branch January 30, 2025 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Landcodes, waarom niet aanhouden van ISO 3166?
3 participants