naturtag.client module#

class naturtag.client.ImageSession(*args, cache_path=PosixPath('/home/docs/.local/share/Naturtag/images.db'), **kwargs)#

Bases: ClientSession

cache_size()#

Get the total cache size in bytes, and the number of cached files

Return type:

str

get_image(photo, url=None, size=None)#

Get an image from the cache, if it exists; otherwise, download and cache a new one

Return type:

bytes

get_pixmap(path=None, photo=None, url=None, size=None)#

Fetch a pixmap from either a local path or remote URL. This does not render the image, so it is safe to run from any thread.

Return type:

QPixmap

class naturtag.client.ObservationDbController(*args, taxon_controller, **kwargs)#

Bases: ObservationController

count(username, **params)#

Get the total number of observations matching the specified criteria

Return type:

int

from_ids(*observation_ids, refresh=False, taxonomy=False, **params)#

Get observations by ID; first from the database, then from the API

Return type:

WrapperPaginator[Observation]

get_user_observations(username, updated_since=None, limit=50, page=1)#

Fetch any new observations from the API since last search, save them to the db, and then return up to limit most recent observations from the db

Return type:

list[Observation]

save(observations)#

Save observations to the database

search(**params)#

Search observations, and save results to the database (for future reference by ID)

Return type:

WrapperPaginator[Observation]

class naturtag.client.TaxonDbController(client)#

Bases: TaxonController

from_ids(*taxon_ids, accept_partial=False, refresh=False, **params)#

Get taxa by ID; first from the database, then from the API

Return type:

WrapperPaginator[Taxon]

search(**params)#

Search taxa, and save results to the database (for future reference by ID)

Return type:

WrapperPaginator[Taxon]

naturtag.client.get_url_hash(url)#

Generate a hash to use as a cache key from an image URL, appended with the file extension

Parameters:

source – File path or URI for image source

Return type:

str

class naturtag.client.iNatDbClient(db_path=PosixPath('/home/docs/.local/share/Naturtag/naturtag.db'), **kwargs)#

Bases: iNatClient

API client class that uses a local SQLite database to cache observations and taxa (when searched by ID)

from_ids(observation_id=None, taxon_id=None)#

Get an iNaturalist observation and/or taxon matching the specified ID(s). If only a taxon ID is provided, the observation will be a placeholder with only the taxon field populated.

Return type:

Optional[Observation]