From 897c3943c1ee2f5b028f1308a5f7483191218b16 Mon Sep 17 00:00:00 2001 From: waldek Date: Mon, 24 May 2021 17:17:28 +0200 Subject: [PATCH] adds argparser to specify which CSV and a question count --- standalone_tui.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/standalone_tui.py b/standalone_tui.py index fbbc7e0..9fdd613 100755 --- a/standalone_tui.py +++ b/standalone_tui.py @@ -1,13 +1,11 @@ #!/usr/bin/python3 import pathlib -import time +import argparse import os -import csv import random from rich.console import Console from rich.markdown import Markdown - from ccpq.lib_ccpq import Question, Database, Game MSG = { @@ -94,13 +92,18 @@ class Tui(object): class Application(object): - def __init__(self, filepath, interface): + def __init__(self, filepath, interface, number): self._db = Database(filepath) + self._number = number self._session = Game() self._interface = interface + def start(self): + pass + + def run(self): - while True: + while self._number > 0: question = self._db.get_question() self._interface.ask_question(question) answer = self._interface.prompt_for_answer() @@ -109,15 +112,21 @@ class Application(object): self._interface.show_success(stat) self._interface.show_response(question) self._interface.show_stats(self._session.get_stats()) + self._number -= 1 + self.quit() def quit(self): self._interface.goodbye() if __name__ == "__main__": - filepath = pathlib.Path("./data/list_book1.csv") + parser = argparse.ArgumentParser() + parser.add_argument("-f", "--file", required=True, help="file to use as database", action="store") + parser.add_argument("-n", "--number", default=10, help="number of questions to ask", type=int, action="store") + args = parser.parse_args() + filepath = pathlib.Path(args.file) interface = Tui() - app = Application(filepath, interface) + app = Application(filepath, interface, args.number) try: app.run() except KeyboardInterrupt: