Enhance finish_task: Update Total Duration prop and format status report like dev_session.py
This commit is contained in:
@@ -76,6 +76,20 @@ def get_status_options(db_id):
|
||||
status = props.get("Status", {}).get("status", {})
|
||||
return [opt["name"] for opt in status.get("options", [])]
|
||||
|
||||
res = request("GET", f"https://api.notion.com/v1/pages/{page_id}")
|
||||
return res.get("properties", {}) if res else {}
|
||||
|
||||
def get_property_value(page_id, prop_name):
|
||||
props = get_page_properties(page_id)
|
||||
if not props: return None
|
||||
prop = props.get(prop_name)
|
||||
if not prop: return None
|
||||
|
||||
if prop["type"] == "number":
|
||||
return prop["number"]
|
||||
# Add other types if needed
|
||||
return None
|
||||
|
||||
def update_page(page_id, props):
|
||||
return request("PATCH", f"https://api.notion.com/v1/pages/{page_id}", {"properties": props})
|
||||
|
||||
|
||||
@@ -21,29 +21,56 @@ def main():
|
||||
|
||||
task_id = session["task_id"]
|
||||
|
||||
# 1. Update Notion
|
||||
# Calculate time
|
||||
start = datetime.fromisoformat(session["start_time"])
|
||||
hours = (datetime.now() - start).total_seconds() / 3600
|
||||
# 1. Calculate Time & Update "Total Duration (h)"
|
||||
start_utc = datetime.fromisoformat(session["start_time"])
|
||||
now_utc = datetime.now()
|
||||
hours_invested = (now_utc - start_utc).total_seconds() / 3600
|
||||
|
||||
# Get current duration
|
||||
# (Skipping read for now, just appending blocks)
|
||||
# Get current duration from Notion to add to it
|
||||
current_duration = notion.get_property_value(task_id, "Total Duration (h)") or 0.0
|
||||
new_total = current_duration + hours_invested
|
||||
|
||||
# Update the number property
|
||||
notion.update_page(task_id, {
|
||||
"Total Duration (h)": {"number": round(new_total, 2)}
|
||||
})
|
||||
|
||||
# 2. Append Status Report Block
|
||||
# Convert UTC to Berlin Time (UTC+1/UTC+2) - simplified fixed offset for now or use library if available
|
||||
# Since we can't easily install pytz/zoneinfo in restricted env, we add 1 hour (Winter) manually or just label it UTC for now.
|
||||
# Better: Use the system time if container timezone is set, otherwise just print formatted string.
|
||||
# Let's assume container is UTC. Berlin is UTC+1 (Winter).
|
||||
|
||||
# Simple Manual TZ adjustment (approximate, since no pytz)
|
||||
# We will just format the string nicely and mention "Session Time"
|
||||
|
||||
timestamp_str = now_utc.strftime('%Y-%m-%d %H:%M UTC')
|
||||
hours_str = f"{int(hours_invested):02d}:{int((hours_invested*60)%60):02d}"
|
||||
|
||||
report_content = (
|
||||
f"Investierte Zeit in dieser Session: {hours_str}\n"
|
||||
f"Neuer Status: Done\n\n"
|
||||
f"Arbeitszusammenfassung:\n{summary}"
|
||||
)
|
||||
|
||||
blocks = [
|
||||
{
|
||||
"object": "block",
|
||||
"type": "heading_2",
|
||||
"heading_2": {"rich_text": [{"text": {"content": f"Update {datetime.now().strftime('%Y-%m-%d %H:%M')}"}}]}
|
||||
"heading_2": {"rich_text": [{"text": {"content": f"🤖 Status-Update ({timestamp_str})"}}] }
|
||||
},
|
||||
{
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"paragraph": {"rich_text": [{"text": {"content": f"Time invested: {hours:.2f}h\n\n{summary}"}}]}
|
||||
"type": "code",
|
||||
"code": {
|
||||
"rich_text": [{"type": "text", "text": {"content": report_content}}],
|
||||
"language": "yaml" # YAML highlighting makes keys look reddish/colored often
|
||||
}
|
||||
}
|
||||
]
|
||||
notion.append_blocks(task_id, blocks)
|
||||
|
||||
# 2. Git Commit
|
||||
# 3. Git Commit
|
||||
subprocess.run(["git", "add", "."])
|
||||
subprocess.run(["git", "commit", "-m", f"[{task_id[:4]}] {summary}"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user