-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
56 lines (42 loc) · 1.13 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config.from_pyfile('config.py')
db = SQLAlchemy(app)
migrate = Migrate(app, db)
class Reversal(db.Model):
__table__name = 'reversal'
id = db.Column(db.Integer, primary_key=True)
path = db.Column(db.String())
result = db.Column(db.String())
def __init__(self, path, result):
self.path = path
self.result = result
def __repr__(self):
return "<id {}>".format(self.id)
def reverse_text(text):
text_l = list(text)
text_l.reverse()
rev = "".join(text_l)
return rev
@app.route("/")
def welcome_reverse():
return """
<h1>Welcome to emocleW.</h1>
<h2>When your request path become reversed.</h2>
<p>Try any path now</p>
"""
@app.route("/<text>")
def reverse_req(text):
reversed = reverse_text(text)
reversal = Reversal(path= text, result=reversed)
db.session.add(reversal)
db.session.commit()
return """
<h1>{}</h1>
""".format(reversed)
if __name__ == '__main__':
app.run()