From 5b8081189885ae0a88e397f929d0dbb62a53fe80 Mon Sep 17 00:00:00 2001 From: Breyten Ernsting Date: Tue, 26 Mar 2024 16:29:40 +0100 Subject: [PATCH] Add a type per government. See #166 --- backend/jodal/locations.py | 27 +++++++++++++++++++++------ backend/mappings/es-locations.json | 3 +++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/backend/jodal/locations.py b/backend/jodal/locations.py index f618afe..0801bc0 100644 --- a/backend/jodal/locations.py +++ b/backend/jodal/locations.py @@ -82,16 +82,21 @@ def fetch(self): def transform(self, item): name = self._sanatize_name(item['key']) + item_type = 'Gemeente' + if name.lower().startswith('provincie'): + item_type = 'Provincie' return super(PoliFlwLocationScraper, self).transform({ 'name': name, 'id': item['key'], - 'source': self.name + 'source': self.name, + 'type': [item_type] }) class OpenspendingCountyLocationScraper(MemoryMixin, BaseLocationScraper): name = 'openspending' url = 'https://www.openspending.nl/api/v1/governments/?kind=county&limit=1000' + item_type = 'Gemeente' def fetch(self): response = super(OpenspendingCountyLocationScraper, self).fetch() @@ -104,13 +109,14 @@ def transform(self, item): 'id': item['code'], # 'https://www.openspending.nl%s' % (item['resource_uri'],), 'kind': item['kind'], 'parent_kind': item['state'], - 'source': self.name + 'source': self.name, + 'type': [self.item_type] }) class OpenspendingProvinceLocationScraper(OpenspendingCountyLocationScraper): name = 'openspending' url = 'https://www.openspending.nl/api/v1/governments/?kind=province&limit=1000' - + item_type = 'Provincie' class OpenBesluitvormingLocationScraper(MemoryMixin, BaseLocationScraper): name = 'openbesluitvorming' @@ -141,11 +147,16 @@ def fetch(self): def transform(self, item): name = item['_source'].get('name', '').replace('Gemeente ', '').replace('(L)','(L.)') + if item['_source']['classification'] == 'municipality': + item_type = 'Gemeente' + else: + item_type = 'Provincie' return super(OpenBesluitvormingLocationScraper, self).transform({ 'name': name, 'id': '%s%s' % (item['_source']['@context']['@base'], item['_source']['@id'],), 'kind': item['_source']['classification'], - 'source': self.name + 'source': self.name, + 'type': [item_type] }) @@ -166,7 +177,8 @@ def transform(self, item): return super(CVDRLocationScraper, self).transform({ 'name': name, 'id': item['id'], - 'source': self.name + 'source': self.name, + 'type': ['Gemeente'] }) @@ -208,7 +220,8 @@ def transform(self, item): return super(WoogleLocationScraper, self).transform({ 'name': name, 'id': item['code'], - 'source': self.name + 'source': self.name, + 'type': ['Gemeente'] }) class LocationsScraperRunner(object): @@ -258,6 +271,7 @@ def extract_municipalities(self, orig_municipalities): 'name': m['Gemeentenaam'], 'id': m['GemeentecodeGM'], 'kind': 'municipality', + 'type': ['Gemeente'], 'source': 'cbs' } municipalities.append(r) @@ -272,6 +286,7 @@ def extract_provinces(self, municipalties): 'name': 'Provincie %s' % (m['Provincienaam'],), 'id': m['ProvinciecodePV'], 'kind': 'province', + 'type': ['Provincie'], 'source': 'cbs'} return list(provinces.values()) diff --git a/backend/mappings/es-locations.json b/backend/mappings/es-locations.json index 46bbe08..5dce815 100644 --- a/backend/mappings/es-locations.json +++ b/backend/mappings/es-locations.json @@ -50,6 +50,9 @@ "source": { "type": "keyword" }, + "type": { + "type": "keyword" + }, "name": { "type": "text", "analyzer": "text_nl",