Move daily briefings to personal scratchpads, project reports under Project Status Reports parent
This commit is contained in:
@@ -10,7 +10,8 @@ CONFIG = {
|
|||||||
"agent_id": "angela-daily-briefing",
|
"agent_id": "angela-daily-briefing",
|
||||||
"instance_id": INSTANCE_ID,
|
"instance_id": INSTANCE_ID,
|
||||||
"user_id": 3,
|
"user_id": 3,
|
||||||
"wiki_parent_doc_id": "65966bd6-4ef8-4b79-9b79-e4aa62b94e96",
|
"wiki_collection_id": "b6efa6b9-44b5-48c1-b82e-2e6efe36e3eb", # Angela's ScratchPad
|
||||||
|
"wiki_parent_doc_id": "410759a9-4a3b-4881-8ad1-3190cefa760f", # Daily Briefings in Angela's ScratchPad
|
||||||
"location": {
|
"location": {
|
||||||
"name": "Providence",
|
"name": "Providence",
|
||||||
"state": "Utah",
|
"state": "Utah",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ with a config dict specifying location, wiki parent, and agent ID.
|
|||||||
import sys
|
import sys
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from shared import (
|
from shared import (
|
||||||
MT, DASHBOARD_API, WIKI_API, WIKI_COLLECTION_ID, MONTH_NAMES,
|
MT, DASHBOARD_API, WIKI_API, WIKI_COLLECTION_ID as DEFAULT_WIKI_COLLECTION, MONTH_NAMES,
|
||||||
api_request, log_run, wiki_headers, find_child_doc, ensure_child_doc,
|
api_request, log_run, wiki_headers, find_child_doc, ensure_child_doc,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -138,6 +138,7 @@ def compose_briefing(config, sections):
|
|||||||
|
|
||||||
def post_to_wiki(config, markdown, date_str):
|
def post_to_wiki(config, markdown, date_str):
|
||||||
"""Post the briefing to wiki under Year/Month hierarchy."""
|
"""Post the briefing to wiki under Year/Month hierarchy."""
|
||||||
|
wiki_collection = config.get("wiki_collection_id", DEFAULT_WIKI_COLLECTION)
|
||||||
wiki_parent_id = config["wiki_parent_doc_id"]
|
wiki_parent_id = config["wiki_parent_doc_id"]
|
||||||
now = datetime.now(MT)
|
now = datetime.now(MT)
|
||||||
year_str = str(now.year)
|
year_str = str(now.year)
|
||||||
@@ -146,14 +147,16 @@ def post_to_wiki(config, markdown, date_str):
|
|||||||
year_id = ensure_child_doc(
|
year_id = ensure_child_doc(
|
||||||
wiki_parent_id, year_str,
|
wiki_parent_id, year_str,
|
||||||
f"Daily briefings for {year_str}.",
|
f"Daily briefings for {year_str}.",
|
||||||
|
collection_id=wiki_collection,
|
||||||
)
|
)
|
||||||
month_id = ensure_child_doc(
|
month_id = ensure_child_doc(
|
||||||
year_id, month_str,
|
year_id, month_str,
|
||||||
f"Daily briefings for {month_str} {year_str}.",
|
f"Daily briefings for {month_str} {year_str}.",
|
||||||
|
collection_id=wiki_collection,
|
||||||
)
|
)
|
||||||
|
|
||||||
title = f"Daily Briefing — {date_str}"
|
title = f"Daily Briefing — {date_str}"
|
||||||
doc_id = find_child_doc(month_id, title)
|
doc_id = find_child_doc(month_id, title, collection_id=wiki_collection)
|
||||||
|
|
||||||
if doc_id:
|
if doc_id:
|
||||||
api_request(
|
api_request(
|
||||||
@@ -169,7 +172,7 @@ def post_to_wiki(config, markdown, date_str):
|
|||||||
data={
|
data={
|
||||||
"title": title,
|
"title": title,
|
||||||
"text": markdown,
|
"text": markdown,
|
||||||
"collectionId": WIKI_COLLECTION_ID,
|
"collectionId": wiki_collection,
|
||||||
"parentDocumentId": month_id,
|
"parentDocumentId": month_id,
|
||||||
"publish": True,
|
"publish": True,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ CONFIG = {
|
|||||||
"agent_id": "eric-daily-briefing",
|
"agent_id": "eric-daily-briefing",
|
||||||
"instance_id": INSTANCE_ID,
|
"instance_id": INSTANCE_ID,
|
||||||
"user_id": 2,
|
"user_id": 2,
|
||||||
"wiki_parent_doc_id": "2a891fe8-579b-450b-a663-de93915896b7",
|
"wiki_collection_id": "5663a756-babe-4997-9d92-d02b53fce392", # Eric's ScratchPad
|
||||||
|
"wiki_parent_doc_id": "e61ba5be-057b-48aa-ab5e-6ecc248eb8c4", # Daily Briefings in Eric's ScratchPad
|
||||||
"location": {
|
"location": {
|
||||||
"name": "Providence",
|
"name": "Providence",
|
||||||
"state": "Utah",
|
"state": "Utah",
|
||||||
|
|||||||
+47
-10
@@ -192,41 +192,78 @@ def fetch_url_content(urls_text):
|
|||||||
|
|
||||||
|
|
||||||
def post_report_to_wiki(report_md, project_name, collection_id):
|
def post_report_to_wiki(report_md, project_name, collection_id):
|
||||||
"""Post the full report to a wiki collection."""
|
"""Post the full report to a wiki collection under 'Project Status Reports' parent."""
|
||||||
if not collection_id:
|
if not collection_id:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
from shared import ensure_child_doc, find_child_doc
|
||||||
|
|
||||||
now = datetime.now(MT)
|
now = datetime.now(MT)
|
||||||
title = f"Project Status — {project_name} — {now.strftime('%Y-%m-%d')}"
|
|
||||||
headers = wiki_headers()
|
headers = wiki_headers()
|
||||||
|
|
||||||
|
# Ensure "Project Status Reports" parent doc exists in this collection
|
||||||
|
reports_parent_id = ensure_child_doc(
|
||||||
|
None, "Project Status Reports",
|
||||||
|
"Automated project status reports generated by the Project Monitor agent.",
|
||||||
|
collection_id=collection_id,
|
||||||
|
)
|
||||||
|
# ensure_child_doc with parent_id=None won't find via parentDocumentId match.
|
||||||
|
# Search manually for root-level doc in this collection.
|
||||||
|
if not reports_parent_id:
|
||||||
|
try:
|
||||||
|
search = api_request(
|
||||||
|
f"{WIKI_API}/documents.search",
|
||||||
|
data={"query": "Project Status Reports", "collectionId": collection_id},
|
||||||
|
headers=headers, method="POST",
|
||||||
|
)
|
||||||
|
for doc in search.get("data", []):
|
||||||
|
d = doc.get("document", {})
|
||||||
|
if d.get("title") == "Project Status Reports" and d.get("collectionId") == collection_id:
|
||||||
|
reports_parent_id = d["id"]
|
||||||
|
break
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if not reports_parent_id:
|
||||||
|
try:
|
||||||
|
result = api_request(
|
||||||
|
f"{WIKI_API}/documents.create",
|
||||||
|
data={"title": "Project Status Reports",
|
||||||
|
"text": "Automated project status reports.",
|
||||||
|
"collectionId": collection_id, "publish": True},
|
||||||
|
headers=headers, method="POST",
|
||||||
|
)
|
||||||
|
reports_parent_id = result["data"]["id"]
|
||||||
|
except Exception:
|
||||||
|
reports_parent_id = None
|
||||||
|
|
||||||
|
title = f"Project Status — {project_name} — {now.strftime('%Y-%m-%d')}"
|
||||||
|
|
||||||
# Check for existing report today
|
# Check for existing report today
|
||||||
try:
|
try:
|
||||||
search = api_request(
|
search = api_request(
|
||||||
f"{WIKI_API}/documents.search",
|
f"{WIKI_API}/documents.search",
|
||||||
data={"query": title, "collectionId": collection_id},
|
data={"query": title, "collectionId": collection_id},
|
||||||
headers=headers,
|
headers=headers, method="POST",
|
||||||
method="POST",
|
|
||||||
)
|
)
|
||||||
for doc in search.get("data", []):
|
for doc in search.get("data", []):
|
||||||
if doc.get("document", {}).get("title") == title:
|
if doc.get("document", {}).get("title") == title:
|
||||||
api_request(
|
api_request(
|
||||||
f"{WIKI_API}/documents.update",
|
f"{WIKI_API}/documents.update",
|
||||||
data={"id": doc["document"]["id"], "text": report_md, "publish": True},
|
data={"id": doc["document"]["id"], "text": report_md, "publish": True},
|
||||||
headers=headers,
|
headers=headers, method="POST",
|
||||||
method="POST",
|
|
||||||
)
|
)
|
||||||
return doc["document"]["id"]
|
return doc["document"]["id"]
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Create new
|
# Create new under the reports parent
|
||||||
try:
|
try:
|
||||||
|
create_data = {"title": title, "text": report_md, "collectionId": collection_id, "publish": True}
|
||||||
|
if reports_parent_id:
|
||||||
|
create_data["parentDocumentId"] = reports_parent_id
|
||||||
result = api_request(
|
result = api_request(
|
||||||
f"{WIKI_API}/documents.create",
|
f"{WIKI_API}/documents.create",
|
||||||
data={"title": title, "text": report_md, "collectionId": collection_id, "publish": True},
|
data=create_data, headers=headers, method="POST",
|
||||||
headers=headers,
|
|
||||||
method="POST",
|
|
||||||
)
|
)
|
||||||
return result["data"]["id"]
|
return result["data"]["id"]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
+7
-5
@@ -81,11 +81,12 @@ def wiki_headers():
|
|||||||
return {"Authorization": f"Bearer {WIKI_TOKEN}"}
|
return {"Authorization": f"Bearer {WIKI_TOKEN}"}
|
||||||
|
|
||||||
|
|
||||||
def find_child_doc(parent_id, title):
|
def find_child_doc(parent_id, title, collection_id=None):
|
||||||
"""Search for a child doc by title under a given parent."""
|
"""Search for a child doc by title under a given parent."""
|
||||||
|
coll = collection_id or WIKI_COLLECTION_ID
|
||||||
result = api_request(
|
result = api_request(
|
||||||
f"{WIKI_API}/documents.search",
|
f"{WIKI_API}/documents.search",
|
||||||
data={"query": title, "collectionId": WIKI_COLLECTION_ID},
|
data={"query": title, "collectionId": coll},
|
||||||
headers=wiki_headers(),
|
headers=wiki_headers(),
|
||||||
method="POST",
|
method="POST",
|
||||||
)
|
)
|
||||||
@@ -96,9 +97,10 @@ def find_child_doc(parent_id, title):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def ensure_child_doc(parent_id, title, body):
|
def ensure_child_doc(parent_id, title, body, collection_id=None):
|
||||||
"""Find or create a child doc under a parent. Returns doc ID."""
|
"""Find or create a child doc under a parent. Returns doc ID."""
|
||||||
doc_id = find_child_doc(parent_id, title)
|
coll = collection_id or WIKI_COLLECTION_ID
|
||||||
|
doc_id = find_child_doc(parent_id, title, collection_id=coll)
|
||||||
if doc_id:
|
if doc_id:
|
||||||
return doc_id
|
return doc_id
|
||||||
result = api_request(
|
result = api_request(
|
||||||
@@ -106,7 +108,7 @@ def ensure_child_doc(parent_id, title, body):
|
|||||||
data={
|
data={
|
||||||
"title": title,
|
"title": title,
|
||||||
"text": body,
|
"text": body,
|
||||||
"collectionId": WIKI_COLLECTION_ID,
|
"collectionId": coll,
|
||||||
"parentDocumentId": parent_id,
|
"parentDocumentId": parent_id,
|
||||||
"publish": True,
|
"publish": True,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user