import weight provider from private

This commit is contained in:
Dima Gerasimov 2020-03-14 19:19:47 +00:00
parent d38c6f8b36
commit 76390e96ab

46
my/body/weight.py Normal file
View file

@ -0,0 +1,46 @@
from datetime import datetime
from typing import NamedTuple, Iterator
from ..common import LazyLogger
from ..error import Res
from ..notes import orgmode
from mycfg import weight as config
log = LazyLogger('my.body.weight')
class Entry(NamedTuple):
dt: datetime
value: float
# TODO comment??
Result = Res[Entry]
def from_orgmode() -> Iterator[Result]:
orgs = orgmode.query()
for o in orgs.query_all(lambda o: o.with_tag('weight')):
try:
# TODO ?? Result type?
created = o.created
heading = o.heading
except Exception as e:
log.exception(e)
yield e
continue
try:
w = float(heading)
except ValueError as e:
log.exception(e)
yield e
continue
# TODO not sure if it's really necessary..
created = config.default_timezone.localize(created)
yield Entry(
dt=created,
value=w,
# TODO add org note content as comment?
)