dots/.scripts/writing/charquestions

55 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import random
import sys
questions_filepath = f"{os.environ['SCRIPTS']}/writing/character-questions.md"
def print_usage():
print(f"{sys.argv[0]} COUNT\n\nwhere COUNT is the number of questions to retrieve")
def get_question_count() -> int:
if len(sys.argv) < 2:
print_usage()
exit(1)
try:
return int(sys.argv[1])
except ValueError:
print_usage()
exit(1)
def get_question_options():
if not os.path.isfile(questions_filepath):
print(f"questions file not located at expected location: {questions_filepath}")
exit(1)
with open(questions_filepath, "r") as f:
return [l.strip() for l in f.readlines()]
def get_random_questions():
count = get_question_count()
candidates = get_question_options()
indices = []
while len(indices) < count:
r = random.randint(0, len(candidates) - 1)
if r in indices and not len(candidates) <= count:
continue
indices.append(r)
return [candidates[idx] for idx in indices]
if __name__ == "__main__":
[print(q) for q in get_random_questions()]