From 7a3cbb89d3eb834acefcb678d2d07c4fe3241cbf Mon Sep 17 00:00:00 2001 From: anonymous <anonymous> Date: Fri, 14 Sep 2018 16:36:59 +0200 Subject: [PATCH] refactors name of Statistikamt Nord harvester --- ckanext/odsh/commands/initialization.py | 53 +++++++++++++++++-- ckanext/odsh/harvesters/__init__.py | 2 +- .../odsh/harvesters/statistiknordharvester.py | 6 +-- setup.py | 2 +- 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/ckanext/odsh/commands/initialization.py b/ckanext/odsh/commands/initialization.py index 28db4935..d7b2a599 100755 --- a/ckanext/odsh/commands/initialization.py +++ b/ckanext/odsh/commands/initialization.py @@ -46,6 +46,7 @@ class Initialization(CkanCommand): ckan_api_client = ckanapi.LocalCKAN() self._handle_organizations(ckan_api_client) + self._handle_harvesters(ckan_api_client) def _handle_organizations(self, ckan_api_client): present_orgs_dict = ckan_api_client.action.organization_list() @@ -76,19 +77,61 @@ class Initialization(CkanCommand): group_dict ) else: - skip_message = 'Skipping creation of group ' + skip_message = 'Skipping creation of organization ' skip_message = skip_message + "{org_key}, as it's already present." print(skip_message.format(org_key=org_key)) + def _handle_harvesters(self, ckan_api_client): + data_dict = {} + harvesters = get_action('harvest_source_list')(self.create_context_with_user(), data_dict) + present_harvesters_list = list() + for harvester in harvesters: + present_harvesters_list.append(harvester["title"]) + + odsh_harvesters = { + "Kiel": { + 'name': "Kiel", + 'url': "https://www.kiel.de/de/kiel_zukunft/statistik_kieler_zahlen/open_data/Kiel_open_data.json", + 'source_type': "kiel", + 'title': "Kiel", + 'active': True, + 'owner_org': "kiel", + 'frequency': "MANUAL" + }, + "Statistikamt-Nord": { + 'name': "Statistikamt-Nord", + 'url': "file:///usr/lib/ckan/default/src/statistik-nord-stripped.xml", + 'source_type': "statistikamt-nord", + 'title': "Statistik-Nord", + 'active': True, + 'owner_org': "statistikamt", + 'frequency': "MANUAL" + } + } + + for harvester_key in odsh_harvesters: + if harvester_key not in present_harvesters_list: + add_message = 'Adding harvester {harvester_key}.'.format( + harvester_key=harvester_key + ) + print(add_message) + harvester_dict = odsh_harvesters[harvester_key] + + get_action('harvester_source_create')(self.create_context_with_user(), harvester_dict) + else: + skip_message = 'Skipping creation of harvester ' + skip_message = skip_message + "{harvester_key}, as it's already present." + print(skip_message.format(harvester_key=harvester_key)) + def _create_and_purge_organization(self, organization_dict): - """Worker method for the actual group addition. - For unpurged groups a purge happens prior.""" + """Worker method for the actual organization addition. + For unpurged organizations a purge happens prior.""" try: get_action('organization_purge')(self.create_context_with_user(), organization_dict) except NotFound: - not_found_message = 'Group {group_name} not found, nothing to purge.'.format( - group_name=organization_dict['name'] + not_found_message = 'Organization {organization_name} not found, nothing to purge.'.format( + organization_name=organization_dict['name'] ) print(not_found_message) finally: diff --git a/ckanext/odsh/harvesters/__init__.py b/ckanext/odsh/harvesters/__init__.py index 9b5e8fc7..f2c8e95d 100755 --- a/ckanext/odsh/harvesters/__init__.py +++ b/ckanext/odsh/harvesters/__init__.py @@ -6,5 +6,5 @@ except ImportError: import pkgutil __path__ = pkgutil.extend_path(__path__, __name__) -from ckanext.odsh.harvesters.statistiknordharvester import StatistikNordHarvester +from ckanext.odsh.harvesters.statistiknordharvester import StatistikamtNordHarvester from ckanext.odsh.harvesters.kielharvester import KielHarvester diff --git a/ckanext/odsh/harvesters/statistiknordharvester.py b/ckanext/odsh/harvesters/statistiknordharvester.py index 4250c305..24094a52 100755 --- a/ckanext/odsh/harvesters/statistiknordharvester.py +++ b/ckanext/odsh/harvesters/statistiknordharvester.py @@ -26,15 +26,15 @@ from ckanext.odsh.harvesters.ckan_mapper import pyjq_mapper log = logging.getLogger(__name__) -class StatistikNordHarvester(HarvesterBase): +class StatistikamtNordHarvester(HarvesterBase): """ A Harvester for Statistikamt Nord """ def info(self): return { - 'name': 'statistik-nord', - 'title': 'Statistik Nord', + 'name': 'statistikamt-nord', + 'title': 'Statistikamt Nord', 'description': 'Harvests Statistikamt Nord', 'form_config_interface': 'Text' } diff --git a/setup.py b/setup.py index cbe81a7f..68cb9f7d 100755 --- a/setup.py +++ b/setup.py @@ -81,7 +81,7 @@ setup( entry_points=''' [ckan.plugins] odsh=ckanext.odsh.plugin:OdshPlugin - statistiknord_harvester=ckanext.odsh.harvesters:StatistikNordHarvester + statistikamtnord_harvester=ckanext.odsh.harvesters:StatistikamtNordHarvester kiel_harvester=ckanext.odsh.harvesters:KielHarvester [paste.paster_command] -- GitLab