-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
36 lines (31 loc) · 1.06 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
import asciify
import flask
import requests
app = flask.Flask(__name__)
app.config['error_format'] = '''
<div style="font-family: Open Sans, Arial; color:#d55;" align="center">
{}
</div>
'''
@app.route('/')
def main():
return flask.render_template('form.html')
@app.route('/asciified/', methods=['POST'])
def asciify_api():
try:
fr = flask.request
img = fr.files['file']
if not img.filename:
try:
img = requests.get(fr.form['imagelink'], stream=True).raw
except requests.exceptions.MissingSchema:
return app.config['error_format'].format('Problem loading URL.')
return asciify.asciify(img,
float(fr.form['charwidth']),
float(fr.form['brightness']),
to='html',
fontsize=float(fr.form['fontsize'])
)
except Exception as e:
app.log_exception(e)
return app.config['error_format'].format('Unknown error occured.')