drop turn_reaction.md: store_turn.py takes no args, outcome captured in next turn description
This commit is contained in:
+8
-28
@@ -1,12 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Append a turn to the story book and clear turn temp files.
|
||||
"""Archive the current turn to the story book and clear turn temp files.
|
||||
|
||||
Usage:
|
||||
python3 scripts/store_turn.py "Dillion stepped into the chamber..."
|
||||
python3 scripts/store_turn.py < reaction.txt
|
||||
python3 tools/store_turn.py
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from datetime import date
|
||||
|
||||
@@ -14,39 +12,21 @@ SESSION = Path(__file__).resolve().parent.parent / 'session'
|
||||
BOOK = SESSION / 'book.md'
|
||||
TURN_DESC = SESSION / 'turn_description.md'
|
||||
TURN_PROMPT = SESSION / 'turn_prompt.md'
|
||||
TURN_REACTION = SESSION / 'turn_reaction.md'
|
||||
|
||||
CLEAR_FILES = [TURN_DESC, TURN_PROMPT, TURN_REACTION]
|
||||
|
||||
|
||||
def get_reaction() -> str:
|
||||
if len(sys.argv) > 1:
|
||||
return sys.argv[1]
|
||||
if not sys.stdin.isatty():
|
||||
return sys.stdin.read().strip()
|
||||
return ''
|
||||
CLEAR_FILES = [TURN_DESC, TURN_PROMPT]
|
||||
|
||||
|
||||
def main():
|
||||
reaction = get_reaction()
|
||||
if not reaction:
|
||||
print("No reaction text provided. Pass as argument or pipe stdin.")
|
||||
sys.exit(1)
|
||||
|
||||
description = TURN_DESC.read_text().strip() if TURN_DESC.exists() else ''
|
||||
if not description:
|
||||
print("Nothing to store — turn_description.md is empty.")
|
||||
return
|
||||
|
||||
timestamp = date.today().isoformat()
|
||||
|
||||
entry_parts = []
|
||||
if description:
|
||||
entry_parts.append(description)
|
||||
if reaction:
|
||||
entry_parts.append(reaction)
|
||||
|
||||
entry = '\n\n'.join(entry_parts)
|
||||
heading = f'\n\n## Turn — {timestamp}\n\n'
|
||||
BOOK.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(BOOK, 'a') as f:
|
||||
f.write(heading + entry + '\n')
|
||||
f.write(heading + description + '\n')
|
||||
|
||||
for fpath in CLEAR_FILES:
|
||||
if fpath.exists():
|
||||
|
||||
Reference in New Issue
Block a user