-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (53 loc) · 1.54 KB
/
main.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
from flask import Flask, render_template
from flask import json
from haiku import Haiku
from lirr import lirr
haiku = Haiku()
l = lirr()
app = Flask(__name__)
app.config['DEBUG'] = True
@app.route('/')
def root():
return render_template('index.html')
@app.route('/haiku')
@app.route('/haiku.json')
@app.route('/haiku/')
def haiku_no_name():
h = haiku.makeHaiku()
return json.jsonify(**h)
@app.route('/haiku/<word>')
def name_haiku(word):
h = haiku.makeHaiku()
return json.jsonify(**h)
@app.route('/syllable/<word>')
def count_syllables(word):
count = haiku.countSyllables(word)
return json.jsonify(**count)
@app.route('/info/<word>')
def get_word_data(word):
return json.jsonify(**haiku.getWordData(word))
@app.route('/similar/<word>')
def similar_words(word):
return json.jsonify(**haiku.getSimilarWords(word))
@app.route('/insult')
@app.route('/insult/')
def insult_none():
return json.jsonify(**haiku.insult())
@app.route('/insult/<name>')
def insult(name="fred"):
return json.jsonify(**haiku.insult(name))
@app.route('/lirr')
def lirr_delay():
return json.jsonify(l.return_delays())
@app.errorhandler(404)
def page_not_found(e):
"""Return a custom 404 error."""
return 'Sorry, nothing at this URL.', 404
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
return response
if __name__ == '__main__':
app.run(host='0.0.0.0')