-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.py
More file actions
67 lines (51 loc) · 2.38 KB
/
Copy pathweb.py
File metadata and controls
67 lines (51 loc) · 2.38 KB
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
from flask import Flask, request, render_template, Markup
import difftext, json
from itertools import groupby
app = Flask(__name__)
@app.route("/")
@app.route("/index")
def index():
return render_template('index.html')
@app.route("/about")
def about():
return render_template('about.html')
@app.route("/compare")
def compare():
return render_template('compare.html')
@app.route("/difference", methods=['GET', 'POST']) #, 'PATCH', 'PUT', 'DELETE' to be supported
def difference():
out =''
if request.method == 'POST':
#html, plan and forms - perhaps need to remove the plain at some point
if request.headers['Content-Type'] == 'text/plain' or request.headers['Content-Type'] == 'application/html' or request.headers['Content-Type'] == 'application/x-www-form-urlencoded':
firsttxt = request.form['old'].splitlines()
secondtxt = request.form['new'].splitlines()
for i in range(len(firsttxt)):
d = difftext.differenceText(firsttxt[i], secondtxt[i])
diff = d.diff_text()
out += Markup('<p id= "'+ str(i) +'">')
#todo figure out how to mark up html with rdfa style tags for differencing
# tei as microtag!!!
for ln in diff.split('\n'):
if ln.startswith('-'):
out += Markup('<span id="first">'+ln[1:]+'</span>')
elif ln.startswith('+'):
out += Markup('<span id="second">'+ln[1:]+'</span>')
elif ln.startswith('?'):
pass
else:
#out += Markup('<div class="unchanged">'+ln+'</div>')
out += ln
out += Markup('</p>')
return render_template('difference.html', out=out)
elif request.headers['Content-Type'] == 'application/json':
out = json.dumps({ "error": "Content-Type Not Supported Yet!" })
elif request.headers['Content-Type'] == 'application/xml':
out = '<?xml version="1.0"?><error>Content-Type Not Supported Yet!</error>'
else:
out = "415 Unsupported Media Type ;)" + request.headers['Content-Type']
return out
else:
return '405 Method not supported yet'
if __name__ == "__main__":
app.run(debug=True)