39 lines
943 B
Python
Executable File
39 lines
943 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""Archive the current turn to the story book and clear turn temp files.
|
|
|
|
Usage:
|
|
python3 tools/store_turn.py
|
|
"""
|
|
|
|
from pathlib import Path
|
|
from datetime import date
|
|
|
|
SESSION = Path(__file__).resolve().parent.parent / 'session'
|
|
BOOK = SESSION / 'book.md'
|
|
TURN_DESC = SESSION / 'turn_description.md'
|
|
|
|
CLEAR_FILES = [TURN_DESC]
|
|
|
|
|
|
def main():
|
|
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()
|
|
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 + description + '\n')
|
|
|
|
for fpath in CLEAR_FILES:
|
|
if fpath.exists():
|
|
fpath.write_text('')
|
|
|
|
print(f"✓ Turn stored → {BOOK}")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|