diff --git a/ckanext/odsh/commands/initialization.py b/ckanext/odsh/commands/initialization.py index 28db49353cd3ed54a780979757afe37efdbf358c..d7b2a5999c6f1b78993cce4d355d71ef39982520 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 9b5e8fc71fbd41c7d3e0387395ed3e9261731eb1..f2c8e95d5fc0406a920339243b96df364538ccd1 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 4250c305c07e79dde70c2a4d01c9529d4e6e511b..24094a52bd23f7416a351e32ee392f719c35f070 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 cbe81a7fab1ca3a6bfdacbd0dee10c2ef924898c..68cb9f7d10456a451ee9250ca59c8f2a8037038f 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]