-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
72 lines (61 loc) · 1.79 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from bottle import Bottle, run, template, request, static_file
from beaker.middleware import SessionMiddleware
from os.path import abspath, dirname, join
import html2text
app = Bottle()
#
# Beaker cookie handler configuration
#
session_options = {
'session.type': 'file',
'session.data_dir': './session/',
'session.auto': True,
}
app_middleware = SessionMiddleware(app,
session_options)
@app.hook('before_request')
def setup_request():
"""
pre-assign request.session for cookie access before every
request
"""
request.session = request.environ['beaker.session']
#
# Static files configuration for CSS, Javascript etc
#
appPath = dirname(abspath('__file__'))
@app.route('/static/css/:filename#.*#', name='css')
def server_static(filename):
return static_file(filename,
root=join(appPath,'static/css'))
@app.route('/static/js/:filename#.*#', name='js')
def server_static(filename):
return static_file(filename,
root=join(appPath,'static/js'))
@app.route('/static/img/:filename#.*#', name='images')
def server_static(filename):
return static_file(filename,
root=join(appPath,'static/img'))
#
# Routing for requests
#
@app.route('/')
@app.post('/')
def main():
output_text = ""
if request.forms.html_content:
h = html2text.HTML2Text()
h.ignore_links = True
html_content = request.forms.html_content
output_text = h.handle(html_content)
return template("index",
converted_text=output_text,
get_url=app.get_url)
#
# Launch the app!
#
if __name__ == "__main__": run(app_middleware,
host="localhost",
port=8080,
debug=True,
reloader=True)