From 76390e96aba67701caedaecfc7e49bb4ce44f52a Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sat, 14 Mar 2020 19:19:47 +0000 Subject: [PATCH] import weight provider from private --- my/body/weight.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 my/body/weight.py diff --git a/my/body/weight.py b/my/body/weight.py new file mode 100644 index 0000000..d97c316 --- /dev/null +++ b/my/body/weight.py @@ -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? + )