30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
"""클립 동작을 templates/actions.json 에서 무작위로 고른다. 한 사람의 a·b 클립이 같은 동작이 되지 않게 겹치지 않게 뽑는다.
|
|
|
|
python3 actions.py --who woman --has outer,bag # 두 줄 출력: a 클립 동작, b 클립 동작
|
|
"""
|
|
|
|
import argparse
|
|
import json
|
|
import random
|
|
from pathlib import Path
|
|
|
|
ACTIONS = Path(__file__).resolve().parent.parent / "templates" / "actions.json"
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--who", choices=["woman", "man"], required=True)
|
|
parser.add_argument("--has", default="", help="그 사람에게 있는 것 (outer, bag 을 쉼표로)")
|
|
parser.add_argument("--n", type=int, default=2)
|
|
args = parser.parse_args()
|
|
|
|
has = {h.strip() for h in args.has.split(",") if h.strip()}
|
|
pool = [a["text"] for a in json.loads(ACTIONS.read_text(encoding="utf-8"))[args.who] if set(a.get("needs", [])) <= has]
|
|
if len(pool) < args.n:
|
|
raise SystemExit(f"{args.who} 동작 후보가 {len(pool)}개라 {args.n}개를 고를 수 없어요")
|
|
print("\n".join(random.SystemRandom().sample(pool, args.n)))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|