Auto-backup: 210 scripts (@ 2026-11-19 07:41)
This commit is contained in:
@@ -78,6 +78,28 @@ def shell(cmd, **kwargs):
|
|||||||
return result.stdout.strip(), result.returncode
|
return result.stdout.strip(), result.returncode
|
||||||
|
|
||||||
|
|
||||||
|
def extract_json(text):
|
||||||
|
"""Extract the first JSON array/object from noisy output.
|
||||||
|
|
||||||
|
Google client libs emit FutureWarning lines on stderr which get merged
|
||||||
|
into stdout by '2>&1' — json.loads() on the raw string then fails.
|
||||||
|
The first bracket found in the text decides the top-level type.
|
||||||
|
"""
|
||||||
|
if not text:
|
||||||
|
return None
|
||||||
|
positions = {c: text.find(c) for c in "[{"}
|
||||||
|
ordered = sorted((c for c in positions if positions[c] != -1), key=lambda c: positions[c])
|
||||||
|
for opener in ordered:
|
||||||
|
closer = "]" if opener == "[" else "}"
|
||||||
|
end = text.rfind(closer)
|
||||||
|
if end > positions[opener]:
|
||||||
|
try:
|
||||||
|
return json.loads(text[positions[opener]:end + 1])
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
# ================================================================
|
# ================================================================
|
||||||
# Section generators
|
# Section generators
|
||||||
# ================================================================
|
# ================================================================
|
||||||
@@ -122,9 +144,10 @@ def get_emails(max_count=5):
|
|||||||
"""Fetch unread emails and format as markdown table rows."""
|
"""Fetch unread emails and format as markdown table rows."""
|
||||||
try:
|
try:
|
||||||
out, _ = shell(
|
out, _ = shell(
|
||||||
f"cd {GAPI.parent} && python3 {GAPI.name} gmail search 'is:unread' --max {max_count} 2>&1"
|
f"cd {GAPI.parent} && python3 {GAPI.name} gmail search 'is:unread' --max {max_count} 2>&1",
|
||||||
|
timeout=60
|
||||||
)
|
)
|
||||||
data = json.loads(out)
|
data = extract_json(out)
|
||||||
if not data:
|
if not data:
|
||||||
return None, 0
|
return None, 0
|
||||||
|
|
||||||
@@ -165,14 +188,15 @@ def get_agenda(date_id_str):
|
|||||||
# Use the dedicated script
|
# Use the dedicated script
|
||||||
script = HERMES_HOME / "skills/productivity/briefing-quotidien/scripts/agenda_all_calendars.py"
|
script = HERMES_HOME / "skills/productivity/briefing-quotidien/scripts/agenda_all_calendars.py"
|
||||||
if script.exists():
|
if script.exists():
|
||||||
out, _ = shell(f"python3 {script} {date_id_str} 2>&1")
|
out, _ = shell(f"python3 {script} {date_id_str} 2>&1", timeout=60)
|
||||||
else:
|
else:
|
||||||
# Fallback: use google_api.py with primary + common calendars
|
# Fallback: use google_api.py with primary + common calendars
|
||||||
out, _ = shell(
|
out, _ = shell(
|
||||||
f"cd {GAPI.parent} && python3 {GAPI.name} calendar list --max 20 2>&1"
|
f"cd {GAPI.parent} && python3 {GAPI.name} calendar list --max 20 2>&1",
|
||||||
|
timeout=60
|
||||||
)
|
)
|
||||||
|
|
||||||
data = json.loads(out)
|
data = extract_json(out)
|
||||||
if not data:
|
if not data:
|
||||||
return None, 0
|
return None, 0
|
||||||
|
|
||||||
@@ -221,6 +245,30 @@ def get_agenda(date_id_str):
|
|||||||
return None, 0
|
return None, 0
|
||||||
|
|
||||||
|
|
||||||
|
def get_tasks():
|
||||||
|
"""Fetch open Google Tasks via fetch_tasks.py (refreshes tasks scope itself)."""
|
||||||
|
try:
|
||||||
|
script = HERMES_HOME / "skills/productivity/briefing-quotidien/scripts/fetch_tasks.py"
|
||||||
|
if not script.exists():
|
||||||
|
return None, 0
|
||||||
|
out, _ = shell(f"python3 {script} 2>/dev/null", timeout=60)
|
||||||
|
data = extract_json(out)
|
||||||
|
if not data or "tasks" not in data:
|
||||||
|
return None, 0
|
||||||
|
details = data.get("details", [])
|
||||||
|
rows = []
|
||||||
|
for t in details[:8]:
|
||||||
|
title = (t.get("title") or "").strip()
|
||||||
|
if not title:
|
||||||
|
continue
|
||||||
|
due = t.get("due", "")
|
||||||
|
due_str = due[:10] if due else "—"
|
||||||
|
rows.append(f"| {title[:90]} | {t.get('list', '?')[:30]} | {due_str} |")
|
||||||
|
return rows, data["tasks"]
|
||||||
|
except Exception:
|
||||||
|
return None, 0
|
||||||
|
|
||||||
|
|
||||||
def get_meteo():
|
def get_meteo():
|
||||||
"""Fetch weather for Beloeil from Open-Meteo."""
|
"""Fetch weather for Beloeil from Open-Meteo."""
|
||||||
try:
|
try:
|
||||||
@@ -791,6 +839,18 @@ def build_markdown(date_id_str, jour, date_complete):
|
|||||||
else:
|
else:
|
||||||
parts.append("📅 Aucun événement aujourd'hui.\n")
|
parts.append("📅 Aucun événement aujourd'hui.\n")
|
||||||
parts.append("---\n")
|
parts.append("---\n")
|
||||||
|
|
||||||
|
# ---- Tâches ----
|
||||||
|
parts.append(f"# ✅ Tâches ouvertes\n")
|
||||||
|
tasks, nb_tasks = get_tasks()
|
||||||
|
if tasks:
|
||||||
|
parts.append(f"| Tâche | Liste | Échéance |")
|
||||||
|
parts.append(f"|:------|:------|:--------:|")
|
||||||
|
parts.extend(tasks)
|
||||||
|
parts.append("")
|
||||||
|
else:
|
||||||
|
parts.append("✅ Aucune tâche ouverte.\n")
|
||||||
|
parts.append("---\n")
|
||||||
|
|
||||||
# ---- Météo ----
|
# ---- Météo ----
|
||||||
parts.append(f"# 🌤️ Météo — Beloeil\n")
|
parts.append(f"# 🌤️ Météo — Beloeil\n")
|
||||||
@@ -933,7 +993,7 @@ def build_markdown(date_id_str, jour, date_complete):
|
|||||||
# ---- Footer ----
|
# ---- Footer ----
|
||||||
parts.append("Bonne journée! ☀️\n")
|
parts.append("Bonne journée! ☀️\n")
|
||||||
|
|
||||||
return "\n".join(parts), nb_emails, nb_events
|
return "\n".join(parts), nb_emails, nb_events, nb_tasks
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -944,7 +1004,7 @@ def main():
|
|||||||
month = date_id_str[4:6]
|
month = date_id_str[4:6]
|
||||||
|
|
||||||
# Build markdown
|
# Build markdown
|
||||||
md, nb_emails, nb_events = build_markdown(date_id_str, jour, date_complete)
|
md, nb_emails, nb_events, nb_tasks = build_markdown(date_id_str, jour, date_complete)
|
||||||
|
|
||||||
# Save
|
# Save
|
||||||
target_dir = BRIEFING_DIR / year / month
|
target_dir = BRIEFING_DIR / year / month
|
||||||
@@ -964,6 +1024,7 @@ def main():
|
|||||||
"link": link,
|
"link": link,
|
||||||
"emails": nb_emails,
|
"emails": nb_emails,
|
||||||
"events": nb_events,
|
"events": nb_events,
|
||||||
|
"tasks": nb_tasks,
|
||||||
}
|
}
|
||||||
print(json.dumps(result, ensure_ascii=False))
|
print(json.dumps(result, ensure_ascii=False))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user