From db69f9bdf12fce8c7f4ac455ea1b54b53913b8bf Mon Sep 17 00:00:00 2001 From: Jordan Cook Date: Mon, 22 Jul 2024 12:58:26 -0500 Subject: [PATCH] Fix conservation status and establishment means --- pyinaturalist_convert/_models.py | 20 ++++++++++++++++---- pyproject.toml | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pyinaturalist_convert/_models.py b/pyinaturalist_convert/_models.py index c0b025b..fbbbc01 100644 --- a/pyinaturalist_convert/_models.py +++ b/pyinaturalist_convert/_models.py @@ -8,6 +8,8 @@ from pyinaturalist import ( Annotation, Comment, + ConservationStatus, + EstablishmentMeans, IconPhoto, Identification, Observation, @@ -199,8 +201,8 @@ def from_model(cls, taxon: Taxon) -> 'DbTaxon': id=taxon.id, ancestor_ids=_join_list(taxon.ancestor_ids), child_ids=_join_list(taxon.child_ids), - conservation_status=taxon.conservation_status, - establishment_means=taxon.establishment_means, + conservation_status=getattr(taxon.conservation_status, 'status_name', ''), + establishment_means=getattr(taxon.establishment_means, 'establishment_means', ''), iconic_taxon_id=taxon.iconic_taxon_id, is_active=taxon.is_active, leaf_taxa_count=taxon.complete_species_count, @@ -218,12 +220,22 @@ def from_model(cls, taxon: Taxon) -> 'DbTaxon': def to_model(self) -> Taxon: photos = _split_photo_urls(self.photo_urls) + c_status = ( + ConservationStatus(status_name=self.conservation_status) + if self.conservation_status + else None + ) + est_means = ( + EstablishmentMeans(establishment_means=self.establishment_means) + if self.establishment_means + else None + ) return Taxon( id=self.id, ancestors=_get_taxa(self.ancestor_ids), children=_get_taxa(self.child_ids), - conservation_status=self.conservation_status, - establishment_means=self.establishment_means, + conservation_status=c_status, + establishment_means=est_means, default_photo=photos[0] if photos else None, iconic_taxon_id=self.iconic_taxon_id, is_active=self.is_active, diff --git a/pyproject.toml b/pyproject.toml index 539e8c8..028b777 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pyinaturalist-convert" -version = "0.6.4" +version = "0.6.5" description = "Data conversion tools for iNaturalist observations and taxonomy" authors = ["Jordan Cook"] license = "MIT"