dronefly-core 0.3.9.dev2__tar.gz → 0.4.1__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.
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/PKG-INFO +2 -2
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/commands/__init__.py +86 -62
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/formatters/generic.py +101 -388
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/menus/__init__.py +1 -0
- dronefly_core-0.4.1/dronefly/core/menus/menu.py +22 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/menus/source.py +8 -3
- dronefly_core-0.4.1/dronefly/core/menus/taxon.py +31 -0
- dronefly_core-0.4.1/dronefly/core/menus/taxon_list.py +369 -0
- dronefly_core-0.4.1/dronefly/core/models/taxon_list.py +10 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/utils/__init__.py +13 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/pyproject.toml +2 -2
- dronefly_core-0.3.9.dev2/dronefly/core/menus/menu.py +0 -13
- dronefly_core-0.3.9.dev2/dronefly/core/menus/taxon_list.py +0 -31
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/LICENSE +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/README.md +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/__init__.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/clients/__init__.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/clients/inat.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/constants.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/formatters/__init__.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/formatters/constants.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/models/__init__.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/models/config.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/models/controlled_terms.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/models/user.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/parsers/__init__.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/parsers/constants.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/parsers/natural.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/parsers/unixlike.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/parsers/url.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/query/__init__.py +0 -0
- {dronefly_core-0.3.9.dev2 → dronefly_core-0.4.1}/dronefly/core/query/query.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dronefly-core
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: Core dronefly components
|
|
5
5
|
License: AGPL-3.0-or-later
|
|
6
6
|
Author: Ben Armstrong
|
|
@@ -14,7 +14,7 @@ Requires-Dist: dateparser (>=1.1.1,<2.0.0)
|
|
|
14
14
|
Requires-Dist: filelock (>=3.13.3,<4.0.0)
|
|
15
15
|
Requires-Dist: html2markdown (>=0.1.7,<0.2.0)
|
|
16
16
|
Requires-Dist: inflect (>=5.3.0,<6.0.0)
|
|
17
|
-
Requires-Dist: pyinaturalist (
|
|
17
|
+
Requires-Dist: pyinaturalist (>=0.20.0,<0.21.0)
|
|
18
18
|
Requires-Dist: rich (>=13.4)
|
|
19
19
|
Description-Content-Type: text/markdown
|
|
20
20
|
|
|
@@ -27,6 +27,7 @@ from ..formatters.generic import (
|
|
|
27
27
|
UserFormatter,
|
|
28
28
|
p,
|
|
29
29
|
)
|
|
30
|
+
from ..menus.taxon_list import TaxonListSource
|
|
30
31
|
from ..models.config import Config
|
|
31
32
|
from ..models.user import User
|
|
32
33
|
from ..query.query import get_base_query_args, QueryResponse
|
|
@@ -61,11 +62,11 @@ class Context:
|
|
|
61
62
|
# paged command results.
|
|
62
63
|
# - Every command providing paged results must:
|
|
63
64
|
# - Set page_formatter to the formatter for the new results.
|
|
64
|
-
# - Set
|
|
65
|
+
# - Set page_number to the initial page number (default: 0).
|
|
65
66
|
# - Therefore, only a single command providing paged results can
|
|
66
67
|
# be active at a time.
|
|
67
|
-
page_formatter: Union[
|
|
68
|
-
|
|
68
|
+
page_formatter: Union[ListFormatter, BaseFormatter] = None
|
|
69
|
+
page_number: int = 0
|
|
69
70
|
per_page: int = 0
|
|
70
71
|
selected: int = 0
|
|
71
72
|
|
|
@@ -110,20 +111,25 @@ class Commands:
|
|
|
110
111
|
def _parse(self, query_str):
|
|
111
112
|
return self.parser.parse(query_str)
|
|
112
113
|
|
|
113
|
-
def _get_formatted_page(
|
|
114
|
+
async def _get_formatted_page(
|
|
114
115
|
self,
|
|
115
|
-
formatter,
|
|
116
|
-
|
|
116
|
+
formatter: Union[ListFormatter, BaseFormatter],
|
|
117
|
+
page_number: int = 0,
|
|
117
118
|
selected: int = 0,
|
|
118
119
|
header: str = None,
|
|
119
120
|
footer: str = None,
|
|
120
121
|
):
|
|
122
|
+
source = getattr(formatter, "source", None)
|
|
121
123
|
if getattr(formatter, "format_page", None):
|
|
122
|
-
|
|
124
|
+
if source:
|
|
125
|
+
page = await source.get_page(page_number)
|
|
126
|
+
markdown_text = formatter.format_page(page, page_number, selected)
|
|
127
|
+
else:
|
|
128
|
+
markdown_text = formatter.format_page(page_number, selected)
|
|
123
129
|
last_page = formatter.last_page()
|
|
124
130
|
if last_page > 0:
|
|
125
131
|
markdown_text = "\n\n".join(
|
|
126
|
-
[markdown_text, f"Page {
|
|
132
|
+
[markdown_text, f"Page {page_number + 1}/{last_page + 1}"]
|
|
127
133
|
)
|
|
128
134
|
else:
|
|
129
135
|
markdown_text = formatter.format()
|
|
@@ -176,7 +182,7 @@ class Commands:
|
|
|
176
182
|
response = markdown_text
|
|
177
183
|
return response
|
|
178
184
|
|
|
179
|
-
def life(self, ctx: Context, *args):
|
|
185
|
+
async def life(self, ctx: Context, *args):
|
|
180
186
|
_args = " ".join(args) or "by me"
|
|
181
187
|
query = self._parse(_args)
|
|
182
188
|
per_rank = query.per or "main"
|
|
@@ -228,26 +234,30 @@ class Commands:
|
|
|
228
234
|
with_index = self.format == Format.rich
|
|
229
235
|
taxon_list = life_list.data
|
|
230
236
|
formatter = TaxonListFormatter(
|
|
231
|
-
taxon_list,
|
|
232
|
-
per_rank,
|
|
233
|
-
query_response,
|
|
234
237
|
with_indent=True,
|
|
235
|
-
per_page=per_page,
|
|
236
238
|
with_index=with_index,
|
|
239
|
+
)
|
|
240
|
+
root_taxon_id = taxon.id if taxon else None
|
|
241
|
+
source = TaxonListSource(
|
|
242
|
+
entries=taxon_list,
|
|
243
|
+
query_response=query_response,
|
|
244
|
+
formatter=formatter,
|
|
245
|
+
root_taxon_id=root_taxon_id,
|
|
246
|
+
per_page=per_page,
|
|
247
|
+
per_rank=per_rank,
|
|
237
248
|
sort_by=sort_by,
|
|
238
249
|
order=order,
|
|
239
250
|
)
|
|
251
|
+
formatter.source = source
|
|
240
252
|
ctx.page_formatter = formatter
|
|
241
|
-
ctx.
|
|
253
|
+
ctx.page_number = 0
|
|
242
254
|
ctx.selected = 0
|
|
243
|
-
title = formatter.format_title()
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
def taxon_list(self, ctx: Context, *args):
|
|
255
|
+
title = formatter.format_title() if source.meta.taxon_count > 0 else None
|
|
256
|
+
return await self._get_formatted_page(
|
|
257
|
+
ctx.page_formatter, ctx.page_number, ctx.selected, header=title
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
async def taxon_list(self, ctx: Context, *args):
|
|
251
261
|
query = self._parse(" ".join(args))
|
|
252
262
|
per_rank = query.per or "child"
|
|
253
263
|
if per_rank not in [*RANK_KEYWORDS, "child"]:
|
|
@@ -330,7 +340,7 @@ class Commands:
|
|
|
330
340
|
_per_rank = "child"
|
|
331
341
|
taxon_list = _taxon_list
|
|
332
342
|
else:
|
|
333
|
-
taxon_list = [*_children, *_descendants.all()]
|
|
343
|
+
taxon_list = [taxon, *_children, *_descendants.all()]
|
|
334
344
|
else:
|
|
335
345
|
taxon_list = _children
|
|
336
346
|
# List all ranks at the same level, not just the specified rank
|
|
@@ -340,53 +350,63 @@ class Commands:
|
|
|
340
350
|
per_page = ctx.per_page
|
|
341
351
|
with_index = self.format == Format.rich
|
|
342
352
|
formatter = TaxonListFormatter(
|
|
343
|
-
taxon_list,
|
|
344
|
-
per_rank=_per_rank,
|
|
345
|
-
query_response=query_response,
|
|
346
353
|
with_indent=True,
|
|
347
|
-
per_page=per_page,
|
|
348
354
|
with_index=with_index,
|
|
355
|
+
short_description=short_description,
|
|
356
|
+
)
|
|
357
|
+
source = TaxonListSource(
|
|
358
|
+
entries=taxon_list,
|
|
359
|
+
query_response=query_response,
|
|
360
|
+
formatter=formatter,
|
|
361
|
+
root_taxon_id=taxon.id,
|
|
362
|
+
per_page=per_page,
|
|
363
|
+
per_rank=_per_rank,
|
|
349
364
|
sort_by=sort_by,
|
|
350
365
|
order=order,
|
|
351
|
-
short_description=short_description,
|
|
352
366
|
)
|
|
367
|
+
formatter.source = source
|
|
368
|
+
title = formatter.format_title() if source.meta.taxon_count > 0 else None
|
|
353
369
|
ctx.page_formatter = formatter
|
|
354
|
-
ctx.
|
|
370
|
+
ctx.page_number = 0
|
|
355
371
|
ctx.selected = 0
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
def next(self, ctx: Context):
|
|
372
|
+
title_lines = [msg] if msg else []
|
|
373
|
+
if title:
|
|
374
|
+
title_lines.append(title)
|
|
375
|
+
title = "\n".join(title_lines)
|
|
376
|
+
return await self._get_formatted_page(
|
|
377
|
+
ctx.page_formatter, ctx.page_number, ctx.selected, header=title
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
async def next(self, ctx: Context):
|
|
365
381
|
if not ctx.page_formatter:
|
|
366
382
|
return "Type a command that has pages first"
|
|
367
|
-
ctx.
|
|
368
|
-
if ctx.
|
|
369
|
-
ctx.
|
|
383
|
+
ctx.page_number += 1
|
|
384
|
+
if ctx.page_number > ctx.page_formatter.last_page():
|
|
385
|
+
ctx.page_number = 0
|
|
370
386
|
ctx.selected = 0
|
|
371
|
-
return self._get_formatted_page(
|
|
387
|
+
return await self._get_formatted_page(
|
|
388
|
+
ctx.page_formatter, ctx.page_number, ctx.selected
|
|
389
|
+
)
|
|
372
390
|
|
|
373
|
-
def page(self, ctx: Context,
|
|
391
|
+
async def page(self, ctx: Context, page_number: int = 1):
|
|
374
392
|
if not ctx.page_formatter:
|
|
375
393
|
return "Type a command that has pages first"
|
|
376
394
|
last_page = ctx.page_formatter.last_page() + 1
|
|
377
|
-
if
|
|
395
|
+
if page_number > last_page or page_number < 1:
|
|
378
396
|
msg = "Specify page 1"
|
|
379
397
|
if last_page > 1:
|
|
380
398
|
msg += f" through {last_page}"
|
|
381
399
|
return msg
|
|
382
|
-
ctx.
|
|
400
|
+
ctx.page_number = page_number - 1
|
|
383
401
|
ctx.selected = 0
|
|
384
|
-
return self._get_formatted_page(
|
|
402
|
+
return await self._get_formatted_page(
|
|
403
|
+
ctx.page_formatter, ctx.page_number, ctx.selected
|
|
404
|
+
)
|
|
385
405
|
|
|
386
|
-
def sel(self, ctx: Context, sel: int = 1):
|
|
406
|
+
async def sel(self, ctx: Context, sel: int = 1):
|
|
387
407
|
if not ctx.page_formatter:
|
|
388
408
|
return "Type a command that has pages first"
|
|
389
|
-
_page = ctx.page_formatter.
|
|
409
|
+
_page = await ctx.page_formatter.source.get_page(ctx.page_number)
|
|
390
410
|
page_len = len(_page)
|
|
391
411
|
if sel > page_len or sel < 1:
|
|
392
412
|
msg = "Specify entry 1"
|
|
@@ -394,23 +414,27 @@ class Commands:
|
|
|
394
414
|
msg += f" through {page_len}"
|
|
395
415
|
return msg
|
|
396
416
|
ctx.selected = sel - 1
|
|
397
|
-
return self._get_formatted_page(
|
|
417
|
+
return await self._get_formatted_page(
|
|
418
|
+
ctx.page_formatter, ctx.page_number, ctx.selected
|
|
419
|
+
)
|
|
398
420
|
|
|
399
|
-
def prev(self, ctx: Context):
|
|
421
|
+
async def prev(self, ctx: Context):
|
|
400
422
|
if not ctx.page_formatter:
|
|
401
423
|
return "Type a command that has pages first"
|
|
402
|
-
ctx.
|
|
403
|
-
if ctx.
|
|
404
|
-
ctx.
|
|
424
|
+
ctx.page_number -= 1
|
|
425
|
+
if ctx.page_number < 0:
|
|
426
|
+
ctx.page_number = ctx.page_formatter.last_page()
|
|
405
427
|
ctx.selected = 0
|
|
406
|
-
return self._get_formatted_page(
|
|
428
|
+
return await self._get_formatted_page(
|
|
429
|
+
ctx.page_formatter, ctx.page_number, ctx.selected
|
|
430
|
+
)
|
|
407
431
|
|
|
408
|
-
def taxon(self, ctx: Context, *args):
|
|
432
|
+
async def taxon(self, ctx: Context, *args):
|
|
409
433
|
taxon = None
|
|
410
434
|
if len(args) == 0 or args[0] == "sel":
|
|
411
435
|
formatter = ctx.page_formatter
|
|
412
|
-
if formatter and getattr(formatter, "
|
|
413
|
-
page = formatter.
|
|
436
|
+
if formatter and getattr(formatter, "source", None):
|
|
437
|
+
page = await formatter.source.get_page(ctx.page_number)
|
|
414
438
|
with self.inat_client.set_ctx(ctx) as client:
|
|
415
439
|
taxon = client.taxa.populate(page[ctx.selected])
|
|
416
440
|
else:
|
|
@@ -434,11 +458,11 @@ class Commands:
|
|
|
434
458
|
lang=ctx.get_inat_user_default("inat_lang"),
|
|
435
459
|
with_url=True,
|
|
436
460
|
)
|
|
437
|
-
response = self._get_formatted_page(formatter)
|
|
461
|
+
response = await self._get_formatted_page(formatter)
|
|
438
462
|
|
|
439
463
|
return response
|
|
440
464
|
|
|
441
|
-
def obs(self, ctx: Context, *args):
|
|
465
|
+
async def obs(self, ctx: Context, *args):
|
|
442
466
|
query = self._parse(" ".join(args))
|
|
443
467
|
# TODO: Handle all query clauses, not just main.terms
|
|
444
468
|
# TODO: Doesn't do any ranking or filtering of results
|
|
@@ -475,11 +499,11 @@ class Commands:
|
|
|
475
499
|
community_taxon_summary=community_taxon_summary,
|
|
476
500
|
with_link=True,
|
|
477
501
|
)
|
|
478
|
-
response = self._get_formatted_page(formatter)
|
|
502
|
+
response = await self._get_formatted_page(formatter)
|
|
479
503
|
|
|
480
504
|
return response
|
|
481
505
|
|
|
482
|
-
def user(self, ctx: Context, user_id: str):
|
|
506
|
+
async def user(self, ctx: Context, user_id: str):
|
|
483
507
|
with self.inat_client.set_ctx(ctx) as client:
|
|
484
508
|
user = None
|
|
485
509
|
try:
|
|
@@ -492,7 +516,7 @@ class Commands:
|
|
|
492
516
|
|
|
493
517
|
return self._format_markdown(UserFormatter(user).format())
|
|
494
518
|
|
|
495
|
-
def user_add(self, ctx: Context, user_abbrev: str, user_id: str):
|
|
519
|
+
async def user_add(self, ctx: Context, user_abbrev: str, user_id: str):
|
|
496
520
|
if user_abbrev != "me":
|
|
497
521
|
return "Only `user add me <user-id>` is supported at this time."
|
|
498
522
|
user_config = self.config.user(ctx.author.id)
|