Skip to content

Commit

Permalink
Add a type per government. See #166
Browse files Browse the repository at this point in the history
  • Loading branch information
breyten committed Mar 26, 2024
1 parent 24726e9 commit 5b80811
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
27 changes: 21 additions & 6 deletions backend/jodal/locations.py
Expand Up @@ -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()
Expand All @@ -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'
Expand Down Expand Up @@ -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]
})


Expand All @@ -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']
})


Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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())

Expand Down
3 changes: 3 additions & 0 deletions backend/mappings/es-locations.json
Expand Up @@ -50,6 +50,9 @@
"source": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
"name": {
"type": "text",
"analyzer": "text_nl",
Expand Down

0 comments on commit 5b80811

Please sign in to comment.