extract todos, add more stuff
This commit is contained in:
parent
942c55fe16
commit
6b74de5493
1 changed files with 19 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from kython import listdir_abs, json_load, JSONType
|
from kython import listdir_abs, json_load, JSONType
|
||||||
from typing import Dict, List, NamedTuple
|
from typing import Dict, List, NamedTuple, Optional
|
||||||
from pytz import UTC
|
from pytz import UTC
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
|
@ -13,6 +13,9 @@ class Entry(NamedTuple):
|
||||||
content: str
|
content: str
|
||||||
link: str
|
link: str
|
||||||
eid: str
|
eid: str
|
||||||
|
annotation: Optional[str]
|
||||||
|
context: str
|
||||||
|
tags: List[str]
|
||||||
|
|
||||||
# TODO guarantee order?
|
# TODO guarantee order?
|
||||||
def _iter():
|
def _iter():
|
||||||
|
@ -35,14 +38,29 @@ def _iter():
|
||||||
eid = i['id']
|
eid = i['id']
|
||||||
link = i['uri']
|
link = i['uri']
|
||||||
dt = datetime.strptime(dts[:-3] + dts[-2:], '%Y-%m-%dT%H:%M:%S.%f%z')
|
dt = datetime.strptime(dts[:-3] + dts[-2:], '%Y-%m-%dT%H:%M:%S.%f%z')
|
||||||
|
txt = i['text']
|
||||||
|
annotation = None if len(txt.strip()) == 0 else txt
|
||||||
|
context = i['links']['incontext']
|
||||||
yield Entry(
|
yield Entry(
|
||||||
dt,
|
dt,
|
||||||
title,
|
title,
|
||||||
content,
|
content,
|
||||||
link,
|
link,
|
||||||
eid,
|
eid,
|
||||||
|
annotation=annotation,
|
||||||
|
context=context,
|
||||||
|
tags=i['tags'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_entries():
|
def get_entries():
|
||||||
return list(_iter())
|
return list(_iter())
|
||||||
|
|
||||||
|
def get_todos():
|
||||||
|
def is_todo(e: Entry) -> bool:
|
||||||
|
if any(t.lower() == 'todo' for t in e.tags):
|
||||||
|
return True
|
||||||
|
if e.annotation is None:
|
||||||
|
return False
|
||||||
|
return e.annotation.lstrip().lower().startswith('todo')
|
||||||
|
return list(filter(is_todo, get_entries()))
|
||||||
|
|
Loading…
Add table
Reference in a new issue