import weight provider from private
This commit is contained in:
parent
d38c6f8b36
commit
76390e96ab
1 changed files with 46 additions and 0 deletions
46
my/body/weight.py
Normal file
46
my/body/weight.py
Normal 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?
|
||||||
|
)
|
Loading…
Add table
Reference in a new issue