dronefly-miner 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.4
2
+ Name: dronefly-miner
3
+ Version: 0.1.0
4
+ Summary: Dronefly downloader and indexer
5
+ Author: Ben Armstrong
6
+ Author-email: Ben Armstrong <synrg@debian.org>
7
+ License-Expression: AGPL-3.0-or-later
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Requires-Dist: alembic>=1.13
12
+ Requires-Dist: fastparquet>=2026.5.0
13
+ Requires-Dist: numpy>=2.4.6
14
+ Requires-Dist: pandas>=3.0.5
15
+ Requires-Dist: parquet>=1.3.1
16
+ Requires-Dist: polars>=1.44.2
17
+ Requires-Dist: pyarrow>=25.0.1
18
+ Requires-Dist: pyinaturalist-convert>=0.9.1
19
+ Requires-Dist: sqlalchemy>=2.0.52
20
+ Requires-Dist: xmltodict>=1.0.4
21
+ Requires-Python: >=3.11, <3.13
22
+ Description-Content-Type: text/markdown
23
+
24
+ # Dronefly Miner
25
+
26
+ This library supports populating and indexing a database for
27
+ [dronefly-core](https://github.com/dronefly-garden/dronefly-core)
28
+ from the biodiversity data sets published by iNaturalist.
29
+
30
+ # Related packages
31
+
32
+ ## Dronefly core
33
+
34
+ The [dronefly-core](https://github.com/dronefly-garden/dronefly-core)
35
+ package is an incomplete rewrite of [Dronefly](https://dronefly.readthedocs.io/)
36
+ Discord bot's core components.
37
+
38
+ ## Dronefly Discord bot
39
+
40
+ Dronefly Discord bot brings [iNaturalist](https://www.inaturalist.org) taxa,
41
+ observations, and other data from the site into conversations on the
42
+ [Discord](https://discord.com) chat platform.
@@ -0,0 +1,19 @@
1
+ # Dronefly Miner
2
+
3
+ This library supports populating and indexing a database for
4
+ [dronefly-core](https://github.com/dronefly-garden/dronefly-core)
5
+ from the biodiversity data sets published by iNaturalist.
6
+
7
+ # Related packages
8
+
9
+ ## Dronefly core
10
+
11
+ The [dronefly-core](https://github.com/dronefly-garden/dronefly-core)
12
+ package is an incomplete rewrite of [Dronefly](https://dronefly.readthedocs.io/)
13
+ Discord bot's core components.
14
+
15
+ ## Dronefly Discord bot
16
+
17
+ Dronefly Discord bot brings [iNaturalist](https://www.inaturalist.org) taxa,
18
+ observations, and other data from the site into conversations on the
19
+ [Discord](https://discord.com) chat platform.
@@ -0,0 +1,84 @@
1
+ from inspect import signature
2
+ import logging
3
+ from platformdirs import user_data_dir
4
+ import os
5
+
6
+ from pyinaturalist import pprint
7
+ from pyinaturalist_convert import enable_logging, get_db_taxa, load_dwca_tables, load_fts_taxa, aggregate_taxon_db, TaxonAutocompleter
8
+
9
+ USER_DATA_PATH = os.path.join(user_data_dir(), "dronefly-miner")
10
+ DB_PATH = os.path.join(USER_DATA_PATH, 'observations.db')
11
+
12
+ logger = logging.getLogger("dronefly.miner")
13
+ logger.setLevel(logging.INFO)
14
+
15
+ def load_fts_data():
16
+ """Load all full text search data.
17
+
18
+ Downloads, builds, and indexes a local database from iNaturalist
19
+ data exported to GBIF as DWCA-A taxonomy and observation data sets,
20
+ supplemented by common names for all languages.
21
+ """
22
+ enable_logging()
23
+ load_dwca_tables(db_path=DB_PATH)
24
+ aggregate_taxon_db(db_path=DB_PATH)
25
+ load_fts_taxa(db_path=DB_PATH, languages='all')
26
+
27
+ def taxon_autocomplete(text: str, language='en', rank=None, autocompleter: TaxonAutocompleter = None):
28
+ """Autocomplete taxa matching text.
29
+
30
+ Autocompletion results are retrieved with a fast lookup against the
31
+ local full-text indexed database.
32
+ """
33
+ global default_taxon_autocompleter
34
+
35
+ def hydrate_fts_taxa(fts_taxa):
36
+ fts_taxon_ids = [t.id for t in fts_taxa]
37
+ _db_taxa = [t for t in get_db_taxa(db_path=DB_PATH, ids=fts_taxon_ids)]
38
+ db_taxa = []
39
+ for i, ft_id in enumerate(fts_taxon_ids):
40
+ taxon = next(t for t in _db_taxa if t.id == ft_id)
41
+ taxon.is_active = True
42
+ taxon.matched_term = fts_taxa[i].name
43
+ db_taxa.append(taxon)
44
+ return db_taxa
45
+ _autocompleter = None
46
+ if autocompleter:
47
+ _autocompleter = autocompleter
48
+ else:
49
+ try:
50
+ default_taxon_autocompleter
51
+ except NameError:
52
+ default_taxon_autocompleter = TaxonAutocompleter(db_path=DB_PATH, limit=10)
53
+ _autocompleter = default_taxon_autocompleter
54
+
55
+ # TODO: Finish https://github.com/dronefly-garden/pyinaturalist-convert/tree/PR-fts-taxon-rank
56
+ # and submit PR upstream. If taxon_rank is approved and incorporated upstream, bump our dependency
57
+ # to the new version, drop the signature check and warning, and unconditionally supply the parameter.
58
+ kwargs = {"language": language}
59
+ if "taxon_rank" in signature(_autocompleter.search).parameters:
60
+ kwargs["taxon_rank"] = rank
61
+ else:
62
+ if rank:
63
+ # Not much else we can do here but notify the bot operator, as the
64
+ # help text claims to support rank filtering, but the bot is not using
65
+ # an autocompleter implementation that supports it.
66
+ logger.warning("TaxonAutocompleter.search has no taxon_rank parameter; ignoring: %s", rank)
67
+ fts_taxa = _autocompleter.search(text, **kwargs)
68
+
69
+ db_taxa = None
70
+ if fts_taxa:
71
+ db_taxa = hydrate_fts_taxa(fts_taxa)
72
+ return db_taxa
73
+
74
+ def ta(text: str, language='en'):
75
+ """Do one taxon_autocomplete and pretty-print the top hit.
76
+
77
+ A convenience method to play with fta searches.
78
+ """
79
+ db_taxa = taxon_autocomplete(text, language=language)
80
+ if db_taxa:
81
+ print(db_taxa[0].full_name)
82
+ pprint(db_taxa[0])
83
+ else:
84
+ print(f"Not found: {text}")
@@ -0,0 +1,61 @@
1
+ [project]
2
+ name = "dronefly-miner"
3
+ version = "0.1.0"
4
+ description = "Dronefly downloader and indexer"
5
+ authors = [{ name = "Ben Armstrong", email = "synrg@debian.org" }]
6
+ requires-python = ">=3.11,<3.13"
7
+ readme = "README.md"
8
+ license = "AGPL-3.0-or-later"
9
+ classifiers = [
10
+ "Programming Language :: Python :: 3",
11
+ "Programming Language :: Python :: 3.11",
12
+ "Programming Language :: Python :: 3.12",
13
+ ]
14
+ dependencies = [
15
+ "alembic>=1.13",
16
+ "fastparquet>=2026.5.0",
17
+ "numpy>=2.4.6",
18
+ "pandas>=3.0.5",
19
+ "parquet>=1.3.1",
20
+ "polars>=1.44.2",
21
+ "pyarrow>=25.0.1",
22
+ "pyinaturalist-convert>=0.9.1",
23
+ "sqlalchemy>=2.0.52",
24
+ "xmltodict>=1.0.4",
25
+ ]
26
+
27
+ [tool.bandit]
28
+ exclude_dirs = ["tests"]
29
+
30
+ [tool.black]
31
+ target-version = ['py311']
32
+
33
+ [dependency-groups]
34
+ dev = [
35
+ "black>=24.3.0,<25",
36
+ "pre-commit>=4.6.0",
37
+ "pytest>=9.0,<10.dev0",
38
+ "pylint>=2.10.2,<3",
39
+ "flake8-pyproject>=1.2.4,<2",
40
+ ]
41
+
42
+ [tool.flake8]
43
+ max-line-length = 100
44
+ extend-ignore = "E203"
45
+
46
+ [tool.pytest.ini_options]
47
+ addopts = "-p no:red-discordbot"
48
+
49
+ [tool.uv]
50
+ default-groups = "all"
51
+
52
+ [tool.uv.build-backend]
53
+ module-name = ["dronefly.miner"]
54
+ module-root = ""
55
+
56
+ [tool.uv.sources]
57
+ dronefly-miner = { workspace = true }
58
+
59
+ [build-system]
60
+ requires = ["uv_build>=0.11.21,<0.12.0"]
61
+ build-backend = "uv_build"