Skip to content

Commit

Permalink
art: [#14] detached waardenlijst generation code from management comm…
Browse files Browse the repository at this point in the history
…and to seperate file and added tests
  • Loading branch information
bart-maykin committed Oct 9, 2024
1 parent ca2051a commit 6215ec9
Show file tree
Hide file tree
Showing 14 changed files with 3,624 additions and 57 deletions.
36 changes: 18 additions & 18 deletions src/woo_publications/fixtures/waardenlijst.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_139c6280",
"naam": "wet of algemeen verbindend voorschrift",
Expand All @@ -13,7 +13,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_3a248e3a",
"naam": "agenda of besluitenlijst bestuurscollege",
Expand All @@ -25,7 +25,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_3baef532",
"naam": "Woo-verzoek of -besluit",
Expand All @@ -37,7 +37,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_40a05794",
"naam": "organisatie en werkwijze",
Expand All @@ -49,7 +49,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_46a81018",
"naam": "beschikking",
Expand All @@ -61,7 +61,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_759721e2",
"naam": "ontwerp van wet- en regelgeving met adviesaanvraag",
Expand All @@ -73,7 +73,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_816e508d",
"naam": "inspanningsverplichting art 3.1 Woo",
Expand All @@ -85,7 +85,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_89ee6784",
"naam": "bereikbaarheidsgegevens",
Expand All @@ -97,7 +97,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_8c840238",
"naam": "bij vertegenwoordigend orgaan ingekomen stuk",
Expand All @@ -109,7 +109,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_8fc2335c",
"naam": "convenant",
Expand All @@ -121,7 +121,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_99a836c7",
"naam": "advies",
Expand All @@ -133,7 +133,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_a870c43d",
"naam": "klachtoordeel",
Expand All @@ -145,7 +145,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_aab6bfc7",
"naam": "overig besluit van algemene strekking",
Expand All @@ -157,7 +157,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_c6cd1213",
"naam": "jaarplan of jaarverslag",
Expand All @@ -169,7 +169,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_c76862ab",
"naam": "vergaderstuk Staten-Generaal",
Expand All @@ -181,7 +181,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_cf268088",
"naam": "subsidieverplichting anders dan met beschikking",
Expand All @@ -193,7 +193,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_db4862c3",
"naam": "vergaderstuk decentrale overheid",
Expand All @@ -205,7 +205,7 @@
},
{
"pk": null,
"model": "metadata.informatiecategorie",
"model": "metadata.informationcategory",
"fields": {
"identifier": "https://identifier.overheid.nl/tooi/def/thes/kern/c_fdaee95e",
"naam": "onderzoeksrapport",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,30 @@
from glom import glom, PathAccessError, Path, T
import json
import requests

from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand

from woo_publications.metadata.constants import InformatieCategorieOrigins
from woo_publications.metadata.utils import WaardenlijstFixture


class Command(BaseCommand):
help = "Used to fetch the gov waardenlijsten data and turn them into a fixture to load the data into the db."

def handle(self, *args, **options):
r = requests.get("https://repository.officiele-overheidspublicaties.nl/waardelijsten/scw_woo_informatiecategorieen/3/json/scw_woo_informatiecategorieen_3.json")
if r.status_code != 200:
raise CommandError("Could not connect with url.")

data = r.json()
if not data:
raise CommandError("Could not retrieve json from url.")

fixture = []

for waardenlijst in data:
# filter out all ids that aren't waardenlijsten
if not waardenlijst.get("@id").split("/")[-1].startswith("c_"):
continue

fixture_entry = {
"pk": None,
"model": "metadata.informatiecategorie"
}

fields = {
"identifier": waardenlijst.get("@id"),
"naam": glom(waardenlijst, Path("http://www.w3.org/2004/02/skos/core#prefLabel", T[0]["@value"]), skip_exc=PathAccessError),
"naam_meervoud": glom(waardenlijst, Path("https://identifier.overheid.nl/tooi/def/ont/prefLabelVoorGroepen", T[0]["@value"]), skip_exc=PathAccessError),
"definitie": glom(waardenlijst, Path("http://www.w3.org/2004/02/skos/core#definition", T[0]["@value"]), skip_exc=PathAccessError),
"oorsprong": InformatieCategorieOrigins.value_list,
"order": int(glom(waardenlijst, Path("http://www.w3.org/ns/shacl#order", T[0]["@value"]), skip_exc=PathAccessError))
}

fixture_entry["fields"] = fields
fixture.append(fixture_entry)

with open('src/woo_publications/fixtures/waardenlijst.json', 'w', encoding='utf-8') as f:
json.dump(fixture, f, ensure_ascii=False, indent=4)
def add_arguments(self, parser):
parser.add_argument(
"--store-db-entries",
action="store_true",
help="Save the fetched waardenlijst data and either update based on identifier or create new entries.",
default=False,
)
parser.add_argument(
"--create-fixture-file",
action="store_true",
help="Turns fetched waardenlijst data into a fixture file.",
default=False,
)

def handle(self, *args, **options):
cls = WaardenlijstFixture(store_db_entries=options["store_db_entries"])
if options["create_fixture_file"]:
cls.create_fixture_file()
else:
self.stdout.write(json.dumps(cls.generate_fixture()))
Loading

0 comments on commit 6215ec9

Please sign in to comment.