This commit is contained in:
Peter Howell 2025-08-29 23:23:58 +00:00
parent 08c8f85889
commit 7794fa26e0
1 changed files with 56 additions and 9 deletions

View File

@ -779,7 +779,49 @@ def insert_usefulinfo_record(parsed):
# Events
if summary_id and isinstance(events, list):
for e in events:
for idx, e in enumerate(events, start=1):
# Diagnostics: validate dt and length
raw_dt = (e or {}).get('dt')
raw_len = (e or {}).get('length')
raw_title = (e or {}).get('title')
raw_desc = (e or {}).get('description')
dt_str = str(raw_dt) if raw_dt is not None else ''
parsed_ok = False
parsed_iso = ''
all_day = False
try:
if dt_str:
# all-day if no explicit time markers
all_day = not (re.search(r"\d\d?:\d\d", dt_str) or re.search(r"\b(am|pm)\b", dt_str, re.I))
p = parse(dt_str)
parsed_ok = True
parsed_iso = p.isoformat()
except Exception as ex_dt:
print("[usefulinfo][event-parse] bad dt:", dt_str, "error:", str(ex_dt))
def _mins(s):
if not s:
return 60
try:
n = int(s)
if n <= 12:
return n * 60
return n
except Exception:
pass
m = re.findall(r"(\d+(?:\.\d+)?)\s*([hm])", str(s), flags=re.I)
total = 0
for num, unit in m:
try:
val = float(num)
total += int(val * 60) if unit.lower() == 'h' else int(val)
except Exception:
pass
return total or 60
computed_minutes = _mins(raw_len)
try:
CUR.execute(
"""
@ -787,12 +829,7 @@ def insert_usefulinfo_record(parsed):
VALUES (%s, %s, %s, %s)
RETURNING id
""",
(
(e or {}).get('dt'),
(e or {}).get('length'),
(e or {}).get('title'),
(e or {}).get('description'),
)
(raw_dt, raw_len, raw_title, raw_desc)
)
evrow = CUR.fetchone()
if evrow and evrow[0]:
@ -800,8 +837,18 @@ def insert_usefulinfo_record(parsed):
"INSERT INTO useful_info_summary_event (summary_id, event_id) VALUES (%s, %s) ON CONFLICT DO NOTHING",
(summary_id, evrow[0])
)
except Exception:
pass
print(f"[usefulinfo] inserted event id={evrow[0]} (summary_id={summary_id}) dt='{dt_str}' parsed={parsed_ok} iso='{parsed_iso}' all_day={all_day} minutes={computed_minutes} title='{raw_title}'")
else:
print(f"[usefulinfo][warn] no event id returned for dt='{dt_str}' title='{raw_title}'")
except Exception as ex_ins:
print("[usefulinfo][event-insert-failed] summary_id=", summary_id,
" event=", e,
" dt_str=", dt_str,
" parsed_ok=", parsed_ok,
" parsed_iso=", parsed_iso,
" all_day=", all_day,
" computed_minutes=", computed_minutes,
" error=", str(ex_ins))
CON.commit()
finally: