adds argparser to specify which CSV and a question count
This commit is contained in:
		
							parent
							
								
									70e0ec408a
								
							
						
					
					
						commit
						897c3943c1
					
				|  | @ -1,13 +1,11 @@ | ||||||
| #!/usr/bin/python3 | #!/usr/bin/python3 | ||||||
| 
 | 
 | ||||||
| import pathlib | import pathlib | ||||||
| import time | import argparse | ||||||
| import os | import os | ||||||
| import csv |  | ||||||
| import random | import random | ||||||
| from rich.console import Console | from rich.console import Console | ||||||
| from rich.markdown import Markdown | from rich.markdown import Markdown | ||||||
| 
 |  | ||||||
| from ccpq.lib_ccpq import Question, Database, Game | from ccpq.lib_ccpq import Question, Database, Game | ||||||
| 
 | 
 | ||||||
| MSG = { | MSG = { | ||||||
|  | @ -94,13 +92,18 @@ class Tui(object): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Application(object): | class Application(object): | ||||||
|     def __init__(self, filepath, interface): |     def __init__(self, filepath, interface, number): | ||||||
|         self._db = Database(filepath) |         self._db = Database(filepath) | ||||||
|  |         self._number = number | ||||||
|         self._session = Game() |         self._session = Game() | ||||||
|         self._interface = interface |         self._interface = interface | ||||||
| 
 | 
 | ||||||
|  |     def start(self): | ||||||
|  |         pass | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|     def run(self): |     def run(self): | ||||||
|         while True: |         while self._number > 0: | ||||||
|             question = self._db.get_question() |             question = self._db.get_question() | ||||||
|             self._interface.ask_question(question) |             self._interface.ask_question(question) | ||||||
|             answer = self._interface.prompt_for_answer() |             answer = self._interface.prompt_for_answer() | ||||||
|  | @ -109,15 +112,21 @@ class Application(object): | ||||||
|             self._interface.show_success(stat) |             self._interface.show_success(stat) | ||||||
|             self._interface.show_response(question) |             self._interface.show_response(question) | ||||||
|             self._interface.show_stats(self._session.get_stats()) |             self._interface.show_stats(self._session.get_stats()) | ||||||
|  |             self._number -= 1 | ||||||
|  |         self.quit() | ||||||
| 
 | 
 | ||||||
|     def quit(self): |     def quit(self): | ||||||
|         self._interface.goodbye() |         self._interface.goodbye() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| if __name__ == "__main__": | 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() |     interface = Tui() | ||||||
|     app = Application(filepath, interface) |     app = Application(filepath, interface, args.number) | ||||||
|     try: |     try: | ||||||
|         app.run() |         app.run() | ||||||
|     except KeyboardInterrupt: |     except KeyboardInterrupt: | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue