Skip to content

Commit 6889455

Browse files
Add http-server
1 parent 7531206 commit 6889455

File tree

8 files changed

+367
-0
lines changed

8 files changed

+367
-0
lines changed

Pipfile

+2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ verify_ssl = true
44
name = "pypi"
55

66
[packages]
7+
flask = "*"
78

89
[dev-packages]
10+
flask = "*"
911

1012
[requires]
1113
python_version = "3.8"

Pipfile.lock

+268
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

__pycache__/game.cpython-38.pyc

218 Bytes
Binary file not shown.

__pycache__/wsgi.cpython-38.pyc

752 Bytes
Binary file not shown.

static/style.css

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* static/style.css */
2+
body {
3+
font-family: sans-serif;
4+
display: flex;
5+
align-items: center;
6+
justify-content: center;
7+
flex-direction: column;
8+
}
9+
.letter {
10+
border: 1px solid #999;
11+
padding: 8px 6px;
12+
width: 24px;
13+
display: inline-block;
14+
text-align: center;
15+
background-color: #333;
16+
color: #eee;
17+
}
18+
#form, #results {
19+
margin: 1em 0;
20+
}
21+
.valid {
22+
color: green;
23+
}
24+
.invalid {
25+
color: red;
26+
}

templates/check.html

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!-- templates/check.html -->
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta charset="utf8" />
6+
<title>Longest Word</title>
7+
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
8+
</head>
9+
<body>
10+
<h1>Longest Word</h1>
11+
<h2>Result</h2>
12+
<div>
13+
{% for letter in grid %}
14+
<span class="letter">{{ letter }}</span>
15+
{% endfor %}
16+
</div>
17+
<div id="results">
18+
Your word: <strong>{{ word }}</strong>.
19+
{% if is_valid %}
20+
<span class="valid">Congrats, it's valid!</span>
21+
{% else %}
22+
<span class="invalid">Sorry, it's invalid...</span>
23+
{% endif %}
24+
</div>
25+
<div>
26+
<a href="/">New game</a>
27+
</div>
28+
</body>
29+
</html>

templates/home.html

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- templates/home.html -->
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta charset="utf8" />
6+
<title>Longest Word</title>
7+
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
8+
</head>
9+
<body>
10+
<h1>Longest Word</h1>
11+
<div>
12+
{% for letter in grid %}
13+
<span class="letter">{{ letter }}</span>
14+
{% endfor %}
15+
</div>
16+
<form action="/check" id="form" method="post">
17+
<input type="hidden" name="grid" value="{{ ''.join(grid) }}">
18+
<input type="text" name="word" onkeyup="this.value = this.value.toUpperCase();">
19+
<button>Check!</button>
20+
</form>
21+
</body>
22+
</html>

wsgi.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# wsgi.py
2+
# pylint: disable=missing-docstring
3+
4+
from flask import Flask, render_template, request
5+
from game import Game
6+
7+
app = Flask(__name__)
8+
9+
@app.route('/')
10+
def home():
11+
game = Game()
12+
return render_template('home.html', grid=game.grid)
13+
14+
@app.route('/check', methods=["POST"])
15+
def check():
16+
game = Game()
17+
game.grid = list(request.form['grid'])
18+
word = request.form['word']
19+
is_valid = game.is_valid(word)
20+
return render_template('check.html', is_valid=is_valid, grid=game.grid, word=word)

0 commit comments

Comments
 (0)