Add fetch_evening_tasks.py script and shared notion_helpers module

Refactors weekly-template's Notion client setup into a shared helper
(with .env/dotenv support and full pagination), and adds a dedicated
evening-prep script so both commands can fall back to script-based
fetching instead of the MCP search/fetch pattern.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
aj.siegel
2026-09-21 23:05:57 -04:00
parent 339f9b1034
commit 20d8c1aedc
8 changed files with 229 additions and 59 deletions

View File

@@ -5,54 +5,42 @@ Returns JSON with projects, tasks, and reading suggestions.
"""
import json
import os
import sys
from datetime import datetime, timedelta
from notion_client import Client
# Initialize Notion client - will use NOTION_TOKEN env var
notion_token = os.getenv('NOTION_TOKEN')
if not notion_token:
print(json.dumps({"error": "NOTION_TOKEN environment variable not set. See scripts/README.md for setup instructions."}), file=sys.stderr)
sys.exit(1)
from notion_helpers import notion, get_data_source_id, query_all, PROJECTS_DB, TASKS_DB, READING_LIST_DB
notion = Client(auth=notion_token)
# Database IDs
PROJECTS_DB = "2c0abd6c450a8090aca3e0b2b0373c17"
TASKS_DB = "2c0abd6c450a805098d3cc0e7d3dfccf"
READING_LIST_DB = "2c4abd6c450a80cbae55c440dd9e2427"
def get_focus_projects():
"""Get projects with 'Focus this week' = true and Status = Active."""
results = notion.databases.query(
database_id=PROJECTS_DB,
def get_active_projects():
"""Get non-personal projects with Status = Active (candidates for weekly focus selection)."""
pages = query_all(
get_data_source_id(PROJECTS_DB),
filter={
"and": [
{
"property": "Focus this week",
"checkbox": {
"equals": True
}
},
{
"property": "Status",
"select": {
"equals": "Active"
}
},
{
"property": "Type",
"select": {
"does_not_equal": "Personal"
}
}
]
}
)
projects = []
for page in results["results"]:
for page in pages:
props = page["properties"]
projects.append({
"id": page["id"],
"url": page["url"],
"name": props["Name"]["title"][0]["plain_text"] if props["Name"]["title"] else "",
"weekly_goal": props["Weekly goal"]["rich_text"][0]["plain_text"] if props["Weekly goal"]["rich_text"] else "",
"focus_this_week": props["Focus this week"]["checkbox"],
"icon": page.get("icon", {}).get("emoji", "")
})
@@ -64,8 +52,8 @@ def get_weekly_tasks():
today = datetime.now().date()
week_end = today + timedelta(days=7)
results = notion.databases.query(
database_id=TASKS_DB,
pages = query_all(
get_data_source_id(TASKS_DB),
filter={
"and": [
{
@@ -91,7 +79,7 @@ def get_weekly_tasks():
)
tasks = []
for page in results["results"]:
for page in pages:
props = page["properties"]
# Get due date
@@ -131,8 +119,8 @@ def get_weekly_tasks():
def get_reading_suggestions():
"""Get articles with Status = 'To Read' or 'In Progress'."""
results = notion.databases.query(
database_id=READING_LIST_DB,
pages = query_all(
get_data_source_id(READING_LIST_DB),
filter={
"or": [
{
@@ -152,7 +140,7 @@ def get_reading_suggestions():
)
articles = []
for page in results["results"]:
for page in pages:
props = page["properties"]
articles.append({
"id": page["id"],
@@ -168,7 +156,7 @@ def get_reading_suggestions():
def main():
try:
data = {
"projects": get_focus_projects(),
"projects": get_active_projects(),
"tasks": get_weekly_tasks(),
"reading": get_reading_suggestions(),
"generated_at": datetime.now().isoformat()