remove threat status text if no iucn data is available

This commit is contained in:
Owen
2024-12-29 20:16:11 +01:00
committed by Owen Rees
parent edf4364498
commit ffe6fca781
5 changed files with 164 additions and 2 deletions
+3 -1
View File
@@ -79,13 +79,15 @@ defmodule PlantIdDiscordBot.PlantNet.Parser do
best_result = hd(data["results"])
other_results = tl(data["results"])
best_guess_name = best_result["species"]["scientificNameWithoutAuthor"]
best_result_iucn_category = best_result["iucn"]["category"]
score = round(best_result["score"] * 100) |> Integer.to_string()
"""
My best guess is **#{best_guess_name}** with a confidence of **#{score}%**. Common names include **#{Enum.join(best_result["species"]["commonNames"], ", ")}**.
[GBIF](<#{best_result["gbif_url"]}>) | [PFAF](<#{best_result["pfaf_url"]}>) | [POWO](<#{best_result["powo_url"]}>)
Threat status: #{best_result["iucn"]["category"]}
#{if best_result_iucn_category, do: "Threat status: #{best_result_iucn_category}", else: ""}
#{get_alternatives(other_results)}
"""