uquiz/uquiz

76 lines
2.4 KiB
Plaintext
Raw Permalink Normal View History

2020-03-13 21:03:23 +00:00
#!/usr/bin/env python3
2020-03-13 23:05:05 +00:00
import sys, os, json, hashlib, subprocess
2020-03-13 21:03:23 +00:00
motd="""
\033c
_
_ _ __ _ _ _(_)____
| | | |/ _` | | | | |_ /
| |_| | (_| | |_| | |/ /
\__,_|\__, |\__,_|_/___|
|_|
uquiz is a simple user based quiz engine
"""
print(motd)
2020-03-13 23:16:38 +00:00
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
""")
2020-03-13 21:03:23 +00:00
sys.exit()
2020-03-13 23:16:38 +00:00
2020-03-13 23:05:05 +00:00
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]
2020-03-13 23:16:38 +00:00
if not filename:
print('Whoops! I cant find that quiz, try specifying the absolute path.')
sys.exit()
2020-03-14 14:25:13 +00:00
print('Using "{}"! wrong quiz file? specify an absolute path (make sure your quiz file is in a .uquiz/ in a homedir)\n'.format(filename))
2020-03-13 22:50:13 +00:00
answers = []
done = False
def hashme(inp):
return hashlib.md5(inp.encode("utf-8")).hexdigest()[:9]
2020-03-13 21:03:23 +00:00
with open(filename, 'r') as file:
2020-03-13 22:50:13 +00:00
data = json.load(file)
print(data["message"])
for question in data["q"]:
2020-03-13 23:06:23 +00:00
print('\nQuestion {}: {}'.format(data["q"].index(question)+1, question['q']))
2020-03-13 22:50:13 +00:00
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
2020-03-13 21:03:23 +00:00