forked from PDXPythonPirates/wordplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·39 lines (26 loc) · 799 Bytes
/
app.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
#!/usr/bin/env python3
from flask import Flask, jsonify, request
import wordplay
app = Flask(__name__)
@app.route("/")
def hello():
return """<h1>Flask is running!</h1>
<p>Try accessing the <a href="/api/v1/data">dummy data</a> endpoint.</p>
<p>Score letters <a href="/api/v1/score?l=wombat">'wombat'</a></p>
"""
@app.route("/api/v1/data")
def dummy_data():
data = {'message': 'looks like it works!',
'values': list(range(9))}
return jsonify(data)
@app.route("/api/v1/score")
def score_word():
letters = request.args.get('l')
score = wordplay.score_word(letters)
result = {'letters': sorted(list(letters)),
'score': score}
return jsonify(result)
def main():
app.run(debug=True)
if __name__ == "__main__":
main()