Improve morning report collectors and add section toggling

- Add is_section_enabled() to support per-section enable/disable in config
- Update Python path from 3.13 to 3.14 for gmail venv
- Disable tasks section by default (enabled: false in config)
- Apply code formatting improvements (black/ruff style)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
OpenCode Test
2026-01-04 23:44:24 -08:00
parent 7ca8caeecb
commit 45b7e4bcf7
5 changed files with 146 additions and 80 deletions

View File

@@ -18,6 +18,7 @@ from collectors import weather, stocks, infra, news
# These may fail if gmail venv not activated
try:
from collectors import gmail, gcal, gtasks
GOOGLE_COLLECTORS = True
except ImportError:
GOOGLE_COLLECTORS = False
@@ -29,10 +30,7 @@ LOG_PATH.parent.mkdir(parents=True, exist_ok=True)
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
handlers=[
logging.FileHandler(LOG_PATH),
logging.StreamHandler()
]
handlers=[logging.FileHandler(LOG_PATH), logging.StreamHandler()],
)
logger = logging.getLogger(__name__)
@@ -58,10 +56,17 @@ def collect_section(name: str, collector_func, config: dict) -> dict:
"section": name,
"icon": "",
"content": f"⚠️ {name} unavailable: {e}",
"error": str(e)
"error": str(e),
}
def is_section_enabled(name: str, config: dict) -> bool:
"""Check if a section is enabled in config."""
section_key = name.lower()
section_config = config.get(section_key, {})
return section_config.get("enabled", True)
def collect_all(config: dict) -> list:
"""Collect all sections in parallel."""
collectors = [
@@ -72,11 +77,12 @@ def collect_all(config: dict) -> list:
]
if GOOGLE_COLLECTORS:
collectors.extend([
("Email", gmail.collect),
("Calendar", gcal.collect),
("Tasks", gtasks.collect),
])
if is_section_enabled("email", config):
collectors.append(("Email", gmail.collect))
if is_section_enabled("calendar", config):
collectors.append(("Calendar", gcal.collect))
if is_section_enabled("tasks", config):
collectors.append(("Tasks", gtasks.collect))
else:
logger.warning("Google collectors not available - run with gmail venv")
@@ -95,12 +101,14 @@ def collect_all(config: dict) -> list:
results.append(result)
except Exception as e:
logger.error(f"Future {name} exception: {e}")
results.append({
"section": name,
"icon": "",
"content": f"⚠️ {name} failed: {e}",
"error": str(e)
})
results.append(
{
"section": name,
"icon": "",
"content": f"⚠️ {name} failed: {e}",
"error": str(e),
}
)
return results
@@ -111,13 +119,21 @@ def render_report(sections: list, config: dict) -> str:
date_str = now.strftime("%a %b %d, %Y")
time_str = now.strftime("%I:%M %p %Z").strip()
lines = [
f"# Morning Report - {date_str}",
""
]
lines = [f"# Morning Report - {date_str}", ""]
# Order sections
order = ["Weather", "Email", "Calendar", "Today", "Stocks", "Tasks", "Infra", "Infrastructure", "News", "Tech News"]
order = [
"Weather",
"Email",
"Calendar",
"Today",
"Stocks",
"Tasks",
"Infra",
"Infrastructure",
"News",
"Tech News",
]
# Sort by order
section_map = {s.get("section", ""): s for s in sections}
@@ -137,10 +153,7 @@ def render_report(sections: list, config: dict) -> str:
lines.append("")
# Footer
lines.extend([
"---",
f"*Generated: {now.strftime('%Y-%m-%d %H:%M:%S')} PT*"
])
lines.extend(["---", f"*Generated: {now.strftime('%Y-%m-%d %H:%M:%S')} PT*"])
return "\n".join(lines)
@@ -148,7 +161,9 @@ def render_report(sections: list, config: dict) -> str:
def save_report(content: str, config: dict) -> Path:
"""Save report to file and archive."""
output_config = config.get("output", {})
output_path = Path(output_config.get("path", "~/.claude/reports/morning.md")).expanduser()
output_path = Path(
output_config.get("path", "~/.claude/reports/morning.md")
).expanduser()
output_path.parent.mkdir(parents=True, exist_ok=True)
# Write main report