This repository has been archived by the owner on Jan 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
65 lines (49 loc) · 1.64 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
""" app.py """
# coding: utf-8
from logging import Formatter
from logging import INFO
from logging import StreamHandler
from logging import getLogger
import csv
import io
import re
from flask import Flask
from flask import request
from flask import render_template
logger = getLogger(__name__) # pylint: disable=invalid-name
handler = StreamHandler() # pylint: disable=invalid-name
handler.setFormatter(Formatter("%(module)s:%(lineno)s %(message)s"))
logger.setLevel(INFO)
logger.addHandler(handler)
app = Flask(__name__) # pylint: disable=invalid-name
@app.route("/", methods=["GET"])
def get_index():
""" GET / """
return render_template("index.html")
@app.route("/", methods=["POST"])
def post_index():
""" POST / """
message_in = request.form["message_in"]
logger.error(message_in)
messages = []
with io.StringIO(message_in) as _f:
_reader = csv.reader(_f, dialect="excel-tab")
for cols in _reader:
if "".join(cols) == "":
continue
cols = [re.sub(r"\r?\n", " <br />", col) for col in cols]
# in backlog markdown, cell "-" lead to break table
cols = [col.replace("-", "") if col == "-" else col for col in cols] # noqa: E501
messages.append(" | ".join(cols))
if len(messages) > 2:
_messages = [messages[0], " | ".join(["----"] * len(messages))]
_messages.extend(messages[1:])
messages = _messages
message_out = "\n".join(messages)
return render_template(
"index.html",
message_in=message_in,
message_out=message_out,
)
if __name__ == '__main__':
app.run(debug=True)