38 lines
No EOL
1,021 B
Python
38 lines
No EOL
1,021 B
Python
from flask import Flask, render_template, send_from_directory, request, redirect
|
|
import rfc2229
|
|
import configparser
|
|
|
|
# Load configuration
|
|
config = configparser.ConfigParser()
|
|
config.read('config.ini')
|
|
server = config['server']['host']
|
|
port = config['server']['port']
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route('/', methods=['GET', 'POST'])
|
|
def home():
|
|
if request.method == 'POST':
|
|
word = request.form['input']
|
|
return redirect(f'/define/{word}')
|
|
else:
|
|
return render_template('index.j2', server=server)
|
|
|
|
@app.route('/about')
|
|
def about():
|
|
return send_from_directory('static', 'about.xht')
|
|
|
|
@app.route('/define/<word>')
|
|
def define(word):
|
|
client = rfc2229.RFC2229Client()
|
|
client.connect(server, port)
|
|
definition = client.define(word)
|
|
client.quit()
|
|
return render_template('define.j2', word=word, definition=definition)
|
|
|
|
@app.route('/style.css')
|
|
def style():
|
|
return send_from_directory('static', 'output.css')
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host="0.0.0.0", port=8080) |