adds argparser to specify which CSV and a question count

This commit is contained in:
waldek 2021-05-24 17:17:28 +02:00
parent 70e0ec408a
commit 897c3943c1
1 changed files with 16 additions and 7 deletions

View File

@ -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: