From 178f99d8333d6a1fc272677bf36f94a7072469f6 Mon Sep 17 00:00:00 2001 From: Mark Brough Date: Thu, 16 Nov 2023 17:06:26 +0100 Subject: [PATCH 1/2] Fix bug where a reporting-org does not exist --- orgidfinder/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/orgidfinder/__init__.py b/orgidfinder/__init__.py index 590684267..b564cc299 100644 --- a/orgidfinder/__init__.py +++ b/orgidfinder/__init__.py @@ -22,7 +22,10 @@ def get_text(el, path, default_lang): def parse_org(organisation): org_id = organisation.id - reporting_org_id = organisation.etree.find('reporting-org').get('ref') + reporting_org = organisation.etree.find('reporting-org') + if not reporting_org: + return None + reporting_org_id = reporting_org.get('ref') if not reporting_org_id or org_id != reporting_org_id: return None From d35c64c873d7a9e9f9bd6c671e1f23bef9a9e6a7 Mon Sep 17 00:00:00 2001 From: Mark Brough Date: Thu, 16 Nov 2023 17:34:59 +0100 Subject: [PATCH 2/2] Handle case where org_info is None --- scraper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scraper.py b/scraper.py index c43fb8ff6..864a474fd 100644 --- a/scraper.py +++ b/scraper.py @@ -28,6 +28,7 @@ def zip_discard_compr(*iterables, sentinel=None): for dataset in iatikit.data().datasets.where(filetype='organisation'): org_infos = orgidfinder.parse_org_file(dataset) for org_info in org_infos: + if org_info is None: continue org_info['org_type'] = guide._org_types.get(org_info['org_type_code']) id_ = quote_plus(org_info['org_id']) with open(Path(f'{output_dir}/data/{id_}.json'), 'w') as f: