fixes some minor bugs
This commit is contained in:
parent
6a78e96bc4
commit
8662634ff5
|
@ -29,7 +29,6 @@ class Question(object):
|
|||
def _clean_data(self):
|
||||
"""
|
||||
TODO needs quite bit of actual cleanup to make the parsing more robust
|
||||
TODO needs a 'private' variable for issue 5
|
||||
"""
|
||||
self._level = self._data[LEVEL].strip()
|
||||
self._question = self._data[QUESTION].strip()
|
||||
|
@ -44,7 +43,6 @@ class Question(object):
|
|||
def dump_json(self):
|
||||
"""
|
||||
dumps all data to JSON for the REST API
|
||||
TODO needs a key to include the date for issue 5
|
||||
"""
|
||||
data = {
|
||||
UUID: self.get_uuid(),
|
||||
|
@ -125,7 +123,7 @@ class Database(object):
|
|||
for row in data:
|
||||
try:
|
||||
question = Question(row)
|
||||
if question.get_level() == self.level:
|
||||
if question.get_level() in self.level:
|
||||
self._db.append(question)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
@ -158,6 +156,9 @@ class Game(object):
|
|||
self.shuffled_list = []
|
||||
|
||||
def setup_players(self):
|
||||
if not self._filepath.is_file():
|
||||
self.add_player("Hans Solo")
|
||||
else:
|
||||
with open(self._filepath, "r") as fp:
|
||||
lines = fp.readlines()
|
||||
for line in lines:
|
||||
|
|
|
@ -30,6 +30,14 @@ DIFFICULTY = {
|
|||
"hard": "102-500",
|
||||
}
|
||||
|
||||
DIFFICULTY_SCALE = [
|
||||
"010-160",
|
||||
"101-400",
|
||||
"101-500",
|
||||
"102-400",
|
||||
"102-500",
|
||||
]
|
||||
|
||||
|
||||
class Tui(object):
|
||||
def __init__(self):
|
||||
|
@ -131,14 +139,13 @@ class Tui(object):
|
|||
class Application(object):
|
||||
def __init__(self, filepath_csv, filepath_players, interface, number, level):
|
||||
self._db = Database(filepath_csv, level)
|
||||
self._number = number
|
||||
self._session = Game(filepath_players)
|
||||
self._number = number * len(self._session.get_all_players())
|
||||
self._interface = interface
|
||||
|
||||
def start(self):
|
||||
pass
|
||||
|
||||
|
||||
def run(self):
|
||||
while self._number > 0:
|
||||
player = self._session.get_random_player()
|
||||
|
@ -167,20 +174,20 @@ class Application(object):
|
|||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-f", "--file", required=True, help="file to use as database", action="store")
|
||||
parser.add_argument("-p", "--players", required=True, help="list of players", action="store")
|
||||
parser.add_argument("-p", "--players", required=False, default="", help="list of players", action="store")
|
||||
parser.add_argument("-n", "--number", default=10, help="number of questions to ask", type=int, action="store")
|
||||
parser.add_argument("-d", "--difficulty", default="easy", help="easy, medium or hard", type=str, action="store")
|
||||
args = parser.parse_args()
|
||||
filepath_csv = pathlib.Path(args.file)
|
||||
filepath_players = pathlib.Path(args.players)
|
||||
if not filepath_csv.exists() or not filepath_players.exists():
|
||||
print("no such file!")
|
||||
if not filepath_csv.exists():
|
||||
print("no such file or directory!")
|
||||
exit(1)
|
||||
try:
|
||||
level = DIFFICULTY[args.difficulty]
|
||||
level = DIFFICULTY_SCALE[0:DIFFICULTY_SCALE.index(DIFFICULTY[args.difficulty]) + 1]
|
||||
except Exception as e:
|
||||
print(e)
|
||||
level = DIFFICULTY["easy"]
|
||||
level = DIFFICULTY_SCALE[0:DIFFICULTY_SCALE.index(DIFFICULTY["easy"])]
|
||||
interface = Tui()
|
||||
app = Application(filepath_csv, filepath_players, interface, args.number, level)
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue