Move daily briefings to personal scratchpads, project reports under Project Status Reports parent
This commit is contained in:
+47
-10
@@ -192,41 +192,78 @@ def fetch_url_content(urls_text):
|
||||
|
||||
|
||||
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:
|
||||
return None
|
||||
|
||||
from shared import ensure_child_doc, find_child_doc
|
||||
|
||||
now = datetime.now(MT)
|
||||
title = f"Project Status — {project_name} — {now.strftime('%Y-%m-%d')}"
|
||||
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
|
||||
try:
|
||||
search = api_request(
|
||||
f"{WIKI_API}/documents.search",
|
||||
data={"query": title, "collectionId": collection_id},
|
||||
headers=headers,
|
||||
method="POST",
|
||||
headers=headers, method="POST",
|
||||
)
|
||||
for doc in search.get("data", []):
|
||||
if doc.get("document", {}).get("title") == title:
|
||||
api_request(
|
||||
f"{WIKI_API}/documents.update",
|
||||
data={"id": doc["document"]["id"], "text": report_md, "publish": True},
|
||||
headers=headers,
|
||||
method="POST",
|
||||
headers=headers, method="POST",
|
||||
)
|
||||
return doc["document"]["id"]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Create new
|
||||
# Create new under the reports parent
|
||||
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(
|
||||
f"{WIKI_API}/documents.create",
|
||||
data={"title": title, "text": report_md, "collectionId": collection_id, "publish": True},
|
||||
headers=headers,
|
||||
method="POST",
|
||||
data=create_data, headers=headers, method="POST",
|
||||
)
|
||||
return result["data"]["id"]
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user