-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmadlibs.py
70 lines (47 loc) · 1.79 KB
/
madlibs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from random import choice
from flask import Flask, render_template, request
# "__name__" is a special Python variable for the name of the current module
# Flask wants to know this to know what any imported things are relative to.
app = Flask(__name__)
AWESOMENESS = [
'awesome', 'terrific', 'fantastic', 'neato', 'fantabulous', 'wowza', 'oh-so-not-meh',
'brilliant', 'ducky', 'coolio', 'incredible', 'wonderful', 'smashing', 'lovely']
@app.route('/')
def start_here():
"""Homepage."""
return "Hi! This is the home page."
@app.route('/hello')
def say_hello():
"""Save hello to user."""
return render_template("hello.html")
@app.route('/greet')
def greet_person():
"""Greet user."""
player = request.args.get("person")
compliment = choice(AWESOMENESS)
return render_template("compliment.html",
person=player,
compliment=compliment)
@app.route('/game')
def show_game_form():
response = request.args.get("response")
if response == "yes":
return render_template("game.html")
else:
return render_template("goodbye.html")
@app.route('/madlib')
def show_madlib_form():
player = request.args.get("person")
color = request.args.get("color")
place = request.args.get("place")
adjective = request.args.get("adjective")
verbs = request.args.getlist("verb")
verbs = [verb.lstrip("utf-8") for verb in verbs]
verbs = " and ".join(verbs)
print verbs
return render_template("madlib.html", person =player, color = color,
place = place, adjective = adjective, verb = verbs)
if __name__ == '__main__':
# debug=True gives us error messages in the browser and also "reloads" our web app
# if we change the code.
app.run(debug=True)