#!/usr/bin/env python3 import sys, os, json, hashlib, subprocess motd=""" \033c _ _ _ __ _ _ _(_)____ | | | |/ _` | | | | |_ / | |_| | (_| | |_| | |/ / \__,_|\__, |\__,_|_/___| |_| uquiz is a simple user based quiz engine """ print(motd) if len(sys.argv) < 2 or sys.argv[1] == 'help': print(""" Hi, welcome to uquiz, lickthecheese's userdir based assessment engine. To get started, type in a test name as the first argument of this command, or make your own test by making a json file in your ~/.uquiz There is not much documentation at the moment of how to make a uquiz compatable file, however you can just look at examples until i make some docs lol """) sys.exit() filename=subprocess.run(['bash -c "find /home/*/.uquiz/* | grep \'{}\' | head -n 1"'.format(sys.argv[1])], shell=True, stdout=subprocess.PIPE).stdout.decode('utf-8')[:-1] if not filename: print('Whoops! I cant find that quiz, try specifying the absolute path.') sys.exit() print('Using "{}"! wrong quiz file? specify an absolute path (make sure your quiz file is in a .uquiz/ in a homedir)\n'.format(filename)) answers = [] done = False def hashme(inp): return hashlib.md5(inp.encode("utf-8")).hexdigest()[:9] with open(filename, 'r') as file: data = json.load(file) print(data["message"]) for question in data["q"]: print('\nQuestion {}: {}'.format(data["q"].index(question)+1, question['q'])) for ans in question["o"]: print("{}) {}".format(data["t"][question["o"].index(ans)],ans)) chosen = 0 while not chosen in data["t"]: chosen = input('> ').lower() answers.append(data["t"].index(chosen)) print('Test done! input the salt to see your score, if you dont have it then just press enter.') while not done: score = 0 nques = 0 salt = input('salt> ') if salt: for i in range(len(answers)): nques+=1 print(str(hashme(salt+data["q"][i]["o"][answers[i]]))) if str(hashme(salt+data["q"][i]["o"][answers[i]])) == data["q"][i]["c"]: score+=1 print("You got {}% ({}/{})".format((score/nques)*100, score, nques)) print("Your answers were: "+" ".join([str(a) for a in answers])) if input("done? (yes)> ") == "yes": done = True