From 2d218d795f99179d6e64183c2c9e169b53c62e49 Mon Sep 17 00:00:00 2001 From: Briar Date: Thu, 21 Mar 2024 23:17:45 -0400 Subject: [PATCH] Find country code from adminlevel --- src/hapi/pipelines/app/pipelines.py | 2 ++ .../pipelines/database/operational_presence.py | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/hapi/pipelines/app/pipelines.py b/src/hapi/pipelines/app/pipelines.py index a1efcef6..42500ab2 100644 --- a/src/hapi/pipelines/app/pipelines.py +++ b/src/hapi/pipelines/app/pipelines.py @@ -226,6 +226,8 @@ def output(self): session=self.session, metadata=self.metadata, admins=self.admins, + adminone=self.adminone, + admintwo=self.admintwo, org=self.org, org_type=self.org_type, sector=self.sector, diff --git a/src/hapi/pipelines/database/operational_presence.py b/src/hapi/pipelines/database/operational_presence.py index a14ebef0..a44ceb8a 100644 --- a/src/hapi/pipelines/database/operational_presence.py +++ b/src/hapi/pipelines/database/operational_presence.py @@ -5,6 +5,7 @@ from typing import Dict from hapi_schema.db_operational_presence import DBOperationalPresence +from hdx.location.adminlevel import AdminLevel from hdx.location.names import clean_name from hdx.utilities.dateparse import parse_date from hdx.utilities.dictandlist import write_list_to_csv @@ -26,6 +27,8 @@ def __init__( session: Session, metadata: Metadata, admins: admins.Admins, + adminone: AdminLevel, + admintwo: AdminLevel, org: Org, org_type: OrgType, sector: Sector, @@ -34,6 +37,8 @@ def __init__( super().__init__(session) self._metadata = metadata self._admins = admins + self._adminone = adminone + self._admintwo = admintwo self._org = org self._org_type = org_type self._sector = sector @@ -85,9 +90,17 @@ def populate(self, debug=False): org_type_orig = values[org_type_name_index][ admin_code ][i] - # TODO: find the country code for get_org_info parameter "location" + country_code = None + if admin_level == "admintwo": + country_code = self._admintwo.pcode_to_iso3.get( + admin_code + ) + if admin_level == "adminone": + country_code = self._admintwo.pcode_to_iso3.get( + admin_code + ) org_info = self._org.get_org_info( - org_name_orig, location="Country code" + org_name_orig, location=country_code ) self._org.add_org_to_lookup( org_name_orig, org_info.get("#org+name")