dronefly-garden / dronefly

Red Discord Bot V3 cogs for naturalists.
Other
16 stars 3 forks source link

Add iNat taxa lookup command #13

Closed synrg closed 5 years ago

synrg commented 5 years ago

A taxa lookup would be a nice 1st feature for #12 , with initial support for a unique match (w. thumbnail). Later, add paged output of matching results when not uniquely matched.

See http://api.inaturalist.org/v1/docs/#!/Taxa/get_taxa and the by-id variant above it.

It was pointed out in #birds @ iNat Discord that the 4 letter shortcodes for birds are in iNat, so this is a twofer. Rather than coding something separately for that (e.g. see input_parsing in https://github.com/dfloer/discord-birdbot ), we could take advantage of that.

I envision:

[p]inat taxon bbpl

Since this uniquely matches https://inaturalist.ca/taxa/4892-Pluvialis-squatarola it would then respond with an embed that:

Similarly, when the binomial name or taxon_id is given, it should show just the one record, e.g.

[p]inat taxon pluvialis squatarola
[p]inat taxon 4892

Example API call & output:

$ curl -sl https://api.inaturalist.org/v1/taxa?q=bbpl | python -m json.tool
{
    "total_results": 1,
    "page": 1,
    "per_page": 30,
    "results": [
        {
            "observations_count": 5304,
            "taxon_schemes_count": 10,
            "ancestry": "48460/1/2/355675/3/67561/4783/4888",
            "is_active": true,
            "flag_counts": {
                "unresolved": 0,
                "resolved": 1
            },
            "wikipedia_url": "http://en.wikipedia.org/wiki/Grey_plover",
            "current_synonymous_taxon_ids": null,
            "iconic_taxon_id": 3,
            "rank_level": 10,
            "taxon_changes_count": 0,
            "atlas_id": null,
            "complete_species_count": null,
            "parent_id": 4888,
            "complete_rank": "subspecies",
            "name": "Pluvialis squatarola",
            "rank": "species",
            "extinct": false,
            "id": 4892,
            "default_photo": {
                "square_url": "https://static.inaturalist.org/photos/10603462/square.jpg?1505927973",
                "attribution": "(c) TroyEcol, all rights reserved, uploaded by Declan Troy",
                "flags": [],
                "medium_url": "https://static.inaturalist.org/photos/10603462/medium.jpg?1505927973",
                "id": 10603462,
                "license_code": null,
                "original_dimensions": {
                    "width": 1024,
                    "height": 683
                },
                "url": "https://static.inaturalist.org/photos/10603462/square.jpg?1505927973"
            },
            "ancestor_ids": [
                48460,
                1,
                2,
                355675,
                3,
                67561,
                4783,
                4888,
                4892
            ],
            "matched_term": "BBPL",
            "iconic_taxon_name": "Aves",
            "preferred_common_name": "Black-bellied Plover"
        }
    ]
}

Support for user-specific regional & personal stats would be a nice future enhancement, giving something that the web doesn't directly support (i.e. user needs to navigate to "Show yours" to see those). That would require that the user authorize the bot with an API token of their own.

synrg commented 5 years ago
synrg commented 5 years ago

See https://api.inaturalist.org/v1/taxa/4892 for full output of all taxa info for the example unique match, from which much of the info specified above can be obtained.

For example, summary of wikipedia description up to a reasonable max length is results[0]["wikipedia_summary"]:

The <b>grey plover</b> (<i>Pluvialis squatarola</i>), known as the <b>black-bellied plover</b>
in North America, is a medium-sized plover breeding in Arctic regions. It is a long-distance migrant,
with a nearly worldwide coastal distribution when not breeding. The genus name is Latin and means
relating to rain, from <i>pluvia</i>, \"rain\". It was believed that golden plovers flocked when rain
was imminent. The species name <i>squatarola</i> is a Latinised version of <i>Sgatarola</i>, a
Venetian name for some kind of...

Also, there is a list of photos at various sizes, e.g. there is results[0]["taxon_photos"]["url"] which is: