Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"chart_game" : "/play/chart_game",
}

# I WANT COMMENTS

TRIVIA_QUESTIONS_LIST = {
1 : "What is 4+5",
2 : "What is 1+9",
Expand Down
63 changes: 0 additions & 63 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,69 +11,6 @@ def leaderboard(name=None):
name = request.args["name"]
return render_template('leaderboard.html', name=name, game_name=directory.GAME_NAME_LIST, game_desc=directory.GAME_DESCRIPTION_LIST, game_link=directory.GAME_LINK_LIST)

def check(code, inp, outp):
try:
exec(code)
except:
return ('Syntax error! Try again!', 0)
for test_case in range(len(inp)):
try:
result = eval('f(' + str(inp[test_case]) + ')')
if result != outp[test_case]:
return ("Wrong Answer! Try again!", 0)
except:
return ("Function error! Try again!", 0)
return ("You passed with %d characters" %(len(code)), len(code))

@app.route('/api/code_golf', methods=['GET', 'POST'])
def golf():
if request.method == 'POST':
content = request.form["code"]
question = request.form["question"]
inp = directory.CODE_GOLF_ANSWERS_LIST[question]["inputs"]
outp = directory.CODE_GOLF_ANSWERS_LIST[question]["outputs"]
result, length = check(content, inp, outp)
return json.dumps({"result": result, "chars": length})
elif request.method == 'GET':
return json.dumps(directory.CODE_GOLF_QUESTIONS_LIST)
return "no"

@app.route('/api/movepaths')
def save_user():
username = request.args["username"]
return redirect(url_for('leaderboard', name=username))


@app.route('/api/passwordgen', methods=['GET'])
def password_generation():
if request.method == 'GET':
pwd = ""
pwd += random.choice(directory.COMMON_WORD_LIST_NOUN)
pwd += random.choice(directory.COMMON_WORD_LIST_VERB)
pwd += random.choice(directory.COMMON_WORD_LIST_NOUN)
pwd += random.choice(directory.COMMON_NUMBER_LIST)
return pwd

@app.route('/api/trivia_game', methods=['GET', 'POST'])
def trivia():
if request.method == 'GET':
key = int(request.args.get('question'))
if key in directory.TRIVIA_QUESTIONS_LIST:
return "%d. %s" % (key, directory.TRIVIA_QUESTIONS_LIST[key])
else:
return "No questions left! Check back later for more!"
elif request.method == 'POST':
answer = normalize(request.form["answer"])
questionNum = int(request.form["question"])

if (directory.TRIVIA_ANSWERS_LIST[questionNum] == answer):
return json.dumps({"result": "Correct!"})
return json.dumps({"result": "Wrong!"})
return "pls"

def normalize(string):
return re.sub(r'\W+', '', string.lower())

@app.route('/play/<gamename>')
def play_game(gamename, username=None):
username = request.args.get('username')
Expand Down