-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_scenario.py
More file actions
52 lines (45 loc) · 1.51 KB
/
set_scenario.py
File metadata and controls
52 lines (45 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Jednorazowy wybór scenariusza na start dnia.
Zapisuje do: ./scenarios_text/active.jsonl (append – ostatnia linia = aktywny)
"""
import json, time, sys
from pathlib import Path
SCEN_DIR = Path("./scenarios_text")
ACTIVE_PATH = SCEN_DIR / "active.jsonl"
def list_ids() -> list[str]:
return sorted(p.stem for p in SCEN_DIR.glob("*.md"))
def set_active(sid: str) -> None:
SCEN_DIR.mkdir(parents=True, exist_ok=True)
ACTIVE_PATH.parent.mkdir(parents=True, exist_ok=True)
rec = {"ts": int(time.time()*1000), "id": sid}
with ACTIVE_PATH.open("a", encoding="utf-8") as f:
f.write(json.dumps(rec, ensure_ascii=False) + "\n")
print(f"[set_scenario] Aktywny scenariusz → {sid} (dopisana linia w {ACTIVE_PATH})")
def main():
ids = list_ids()
if not ids:
print("Brak plików scenariuszy w ./scenarios_text/*.md")
sys.exit(1)
if len(sys.argv) >= 2:
sid = sys.argv[1]
if sid not in ids:
print("Nieznany scenariusz. Dostępne:", ", ".join(ids))
sys.exit(2)
set_active(sid)
return
print("Dostępne scenariusze:")
for i, s in enumerate(ids, 1):
print(f" {i}. {s}")
try:
idx = int(input("Wybierz numer scenariusza: ").strip())
except Exception:
print("Niepoprawny numer.")
sys.exit(3)
if not (1 <= idx <= len(ids)):
print("Poza zakresem.")
sys.exit(4)
set_active(ids[idx-1])
if __name__ == "__main__":
main()