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