my.kobo: add hightlights method to return Hightlight objects iteratively
also minor cleanup
This commit is contained in:
parent
d88a1b9933
commit
edea2c2e75
1 changed files with 38 additions and 22 deletions
60
my/kobo.py
60
my/kobo.py
|
@ -1,54 +1,69 @@
|
||||||
"""
|
"""
|
||||||
[[https://uk.kobobooks.com/products/kobo-aura-one][Kobo]] e-ink reader: annotations and reading stats
|
[[https://uk.kobobooks.com/products/kobo-aura-one][Kobo]] e-ink reader: annotations and reading stats
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
REQUIRES = [
|
REQUIRES = [
|
||||||
'kobuddy',
|
'kobuddy',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import Iterator
|
||||||
|
|
||||||
from .core import Paths, dataclass
|
from my.core import (
|
||||||
from my.config import kobo as user_config
|
get_files,
|
||||||
@dataclass
|
stat,
|
||||||
class kobo(user_config):
|
Paths,
|
||||||
'''
|
Stats,
|
||||||
Uses [[https://github.com/karlicoss/kobuddy#as-a-backup-tool][kobuddy]] outputs.
|
)
|
||||||
'''
|
from my.core.cfg import make_config
|
||||||
# path[s]/glob to the exported databases
|
import my.config
|
||||||
export_path: Paths
|
|
||||||
|
|
||||||
|
|
||||||
from .core.cfg import make_config
|
|
||||||
config = make_config(kobo)
|
|
||||||
|
|
||||||
from .core import get_files
|
|
||||||
import kobuddy
|
import kobuddy
|
||||||
# todo not sure about this glob..
|
|
||||||
kobuddy.DATABASES = list(get_files(config.export_path, glob='*.sqlite'))
|
|
||||||
|
|
||||||
#########################
|
|
||||||
|
|
||||||
# hmm, explicit imports make pylint a bit happier?
|
|
||||||
from kobuddy import Highlight, get_highlights
|
from kobuddy import Highlight, get_highlights
|
||||||
from kobuddy import *
|
from kobuddy import *
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class kobo(my.config.kobo):
|
||||||
|
'''
|
||||||
|
Uses [[https://github.com/karlicoss/kobuddy#as-a-backup-tool][kobuddy]] outputs.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# path[s]/glob to the exported databases
|
||||||
|
export_path: Paths
|
||||||
|
|
||||||
|
|
||||||
|
config = make_config(kobo)
|
||||||
|
|
||||||
|
# TODO not ideal to set it here.. should switch kobuddy to use a proper DAL
|
||||||
|
kobuddy.DATABASES = list(get_files(config.export_path))
|
||||||
|
|
||||||
|
|
||||||
|
def highlights() -> Iterator[Highlight]:
|
||||||
|
return kobuddy._iter_highlights()
|
||||||
|
|
||||||
|
|
||||||
from .core import stat, Stats
|
|
||||||
def stats() -> Stats:
|
def stats() -> Stats:
|
||||||
return stat(get_highlights)
|
return stat(highlights)
|
||||||
|
|
||||||
|
|
||||||
## TODO hmm. not sure if all this really belongs here?... perhaps orger?
|
## TODO hmm. not sure if all this really belongs here?... perhaps orger?
|
||||||
|
|
||||||
|
|
||||||
from typing import Callable, Union, List
|
from typing import Callable, Union, List
|
||||||
|
|
||||||
# TODO maybe type over T?
|
# TODO maybe type over T?
|
||||||
_Predicate = Callable[[str], bool]
|
_Predicate = Callable[[str], bool]
|
||||||
Predicatish = Union[str, _Predicate]
|
Predicatish = Union[str, _Predicate]
|
||||||
|
|
||||||
|
|
||||||
def from_predicatish(p: Predicatish) -> _Predicate:
|
def from_predicatish(p: Predicatish) -> _Predicate:
|
||||||
if isinstance(p, str):
|
if isinstance(p, str):
|
||||||
|
|
||||||
def ff(s):
|
def ff(s):
|
||||||
return s == p
|
return s == p
|
||||||
|
|
||||||
return ff
|
return ff
|
||||||
else:
|
else:
|
||||||
return p
|
return p
|
||||||
|
@ -69,6 +84,7 @@ def get_todos() -> List[Highlight]:
|
||||||
if ann is None:
|
if ann is None:
|
||||||
ann = ''
|
ann = ''
|
||||||
return 'todo' in ann.lower().split()
|
return 'todo' in ann.lower().split()
|
||||||
|
|
||||||
return by_annotation(with_todo)
|
return by_annotation(with_todo)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue