-
Notifications
You must be signed in to change notification settings - Fork 59
/
instapaper.py
70 lines (46 loc) 路 1.38 KB
/
instapaper.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
69
70
"""
[[https://www.instapaper.com][Instapaper]] bookmarks, highlights and annotations
"""
REQUIRES = [
'git+https://github.com/karlicoss/instapexport',
]
from dataclasses import dataclass
from .core import Paths
from my.config import instapaper as user_config
@dataclass
class instapaper(user_config):
'''
Uses [[https://github.com/karlicoss/instapexport][instapexport]] outputs.
'''
# path[s]/glob to the exported JSON data
export_path : Paths
from .core.cfg import make_config
config = make_config(instapaper)
try:
from instapexport import dal
except ModuleNotFoundError as e:
from my.core.hpi_compat import pre_pip_dal_handler
dal = pre_pip_dal_handler('instapexport', e, config, requires=REQUIRES)
############################
Highlight = dal.Highlight
Bookmark = dal.Bookmark
Page = dal.Page
from typing import Sequence, Iterable
from pathlib import Path
from .core import get_files
def inputs() -> Sequence[Path]:
return get_files(config.export_path)
def _dal() -> dal.DAL:
return dal.DAL(inputs())
def pages() -> Iterable[Page]:
return _dal().pages()
def stats():
from .core import stat
return stat(pages)
### misc
# TODO dunno, move this to private?
def is_todo(hl: Highlight) -> bool:
note = hl.note or ''
note = note.lstrip().lower()
return note.startswith('todo')
get_pages = pages # todo also deprecate..