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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

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))

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?
1 participant