fix todos retrieval
This commit is contained in:
parent
03b937fd3b
commit
71e04643a4
1 changed files with 18 additions and 9 deletions
|
@ -2,7 +2,7 @@ from datetime import datetime
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import pytz
|
import pytz
|
||||||
from typing import NamedTuple, Optional, List, Dict
|
from typing import NamedTuple, Optional, List, Dict, Iterator, Tuple
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from kython import group_by_key
|
from kython import group_by_key
|
||||||
|
@ -52,9 +52,13 @@ def make_dt(time) -> datetime:
|
||||||
return pytz.utc.localize(datetime.utcfromtimestamp(time))
|
return pytz.utc.localize(datetime.utcfromtimestamp(time))
|
||||||
|
|
||||||
|
|
||||||
def get_stuff(all=True):
|
BDict = Dict[Bid, Bookmark]
|
||||||
all_bks: Dict[Bid, Bookmark] = OrderedDict()
|
HDict = Dict[Hid, Highlight]
|
||||||
all_hls: Dict[Hid, Highlight] = OrderedDict()
|
|
||||||
|
|
||||||
|
def get_stuff(all=True) -> Tuple[BDict, HDict]:
|
||||||
|
all_bks: BDict = OrderedDict()
|
||||||
|
all_hls: HDict = OrderedDict()
|
||||||
# TODO can restore url by bookmark id
|
# TODO can restore url by bookmark id
|
||||||
for f in get_files():
|
for f in get_files():
|
||||||
with f.open('r') as fo:
|
with f.open('r') as fo:
|
||||||
|
@ -91,18 +95,18 @@ def get_stuff(all=True):
|
||||||
|
|
||||||
return all_bks, all_hls
|
return all_bks, all_hls
|
||||||
|
|
||||||
def iter_highlights():
|
def iter_highlights() -> Iterator[Highlight]:
|
||||||
return iter(get_stuff()[1])
|
return iter(get_stuff()[1].values())
|
||||||
|
|
||||||
|
|
||||||
def get_highlights():
|
def get_highlights() -> List[Highlight]:
|
||||||
return list(iter_highlights())
|
return list(iter_highlights())
|
||||||
|
|
||||||
|
|
||||||
def get_todos():
|
def get_todos() -> List[Highlight]:
|
||||||
def is_todo(h):
|
def is_todo(h):
|
||||||
return h.note is not None and h.note.lstrip().lower().startswith('todo')
|
return h.note is not None and h.note.lstrip().lower().startswith('todo')
|
||||||
return list(filter(is_todo, get_highlights()))
|
return list(filter(is_todo, iter_highlights()))
|
||||||
|
|
||||||
|
|
||||||
def get_pages() -> List[Page]:
|
def get_pages() -> List[Page]:
|
||||||
|
@ -118,6 +122,11 @@ def get_pages() -> List[Page]:
|
||||||
return pages
|
return pages
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_todos():
|
||||||
|
for t in get_todos():
|
||||||
|
print(t)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
for h in get_todos():
|
for h in get_todos():
|
||||||
print(h)
|
print(h)
|
||||||
|
|
Loading…
Add table
Reference in a new issue