my.body.blood: prettify, add stat()

This commit is contained in:
Dima Gerasimov 2020-09-01 18:43:37 +01:00 committed by karlicoss
parent efea669a3e
commit 743312a87b
3 changed files with 91 additions and 51 deletions

21
my/core/orgmode.py Normal file
View file

@ -0,0 +1,21 @@
"""
Various helpers for reading org-mode data
"""
from datetime import datetime
def parse_org_datetime(s: str) -> datetime:
s = s.strip('[]')
for fmt, cl in [
("%Y-%m-%d %a %H:%M", datetime),
("%Y-%m-%d %H:%M" , datetime),
# todo not sure about these... fallback on 00:00?
# ("%Y-%m-%d %a" , date),
# ("%Y-%m-%d" , date),
]:
try:
return datetime.strptime(s, fmt)
except ValueError:
continue
else:
raise RuntimeError(f"Bad datetime string {s}")