-
Notifications
You must be signed in to change notification settings - Fork 59
/
pocket.py
68 lines (47 loc) 路 1.45 KB
/
pocket.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
[[https://getpocket.com][Pocket]] bookmarks and highlights
"""
REQUIRES = [
'git+https://github.com/karlicoss/pockexport',
]
from dataclasses import dataclass
from typing import TYPE_CHECKING
from .core import Paths
from my.config import pocket as user_config
@dataclass
class pocket(user_config):
'''
Uses [[https://github.com/karlicoss/pockexport][pockexport]] outputs
'''
# paths[s]/glob to the exported JSON data
export_path: Paths
from .core.cfg import make_config
config = make_config(pocket)
try:
from pockexport import dal
except ModuleNotFoundError as e:
from my.core.hpi_compat import pre_pip_dal_handler
dal = pre_pip_dal_handler('pockexport', e, config, requires=REQUIRES)
############################
Article = dal.Article
from typing import Sequence, Iterable
# todo not sure if should be defensive against empty?
def _dal() -> dal.DAL:
from .core import get_files
inputs = get_files(config.export_path)
return dal.DAL(inputs)
def articles() -> Iterable[Article]:
yield from _dal().articles()
from .core import stat, Stats
def stats() -> Stats:
from itertools import chain
from more_itertools import ilen
return {
**stat(articles),
'highlights': ilen(chain.from_iterable(a.highlights for a in articles())),
}
# todo deprecate?
if not TYPE_CHECKING:
# "deprecate" by hiding from mypy
def get_articles() -> Sequence[Article]:
return list(articles())