Skip to content

Commit

Permalink
Fix conservation status and establishment means
Browse files Browse the repository at this point in the history
  • Loading branch information
JWCook committed Jul 22, 2024
1 parent 2850e58 commit db69f9b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions pyinaturalist_convert/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from pyinaturalist import (
Annotation,
Comment,
ConservationStatus,
EstablishmentMeans,
IconPhoto,
Identification,
Observation,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit db69f9b

Please sign in to comment.