kopia lustrzana https://github.com/dgtlmoon/changedetection.io
Refactor slightly confusing difference build function
rodzic
801b50cb5b
commit
e7e3eb36c0
|
@ -185,30 +185,35 @@ def diff_history_page(uuid):
|
||||||
watch = datastore.data['watching'][uuid]
|
watch = datastore.data['watching'][uuid]
|
||||||
|
|
||||||
dates = list(watch['history'].keys())
|
dates = list(watch['history'].keys())
|
||||||
|
# Convert to int, sort and back to str again
|
||||||
dates = [int(i) for i in dates]
|
dates = [int(i) for i in dates]
|
||||||
dates.sort(reverse=True)
|
dates.sort(reverse=True)
|
||||||
dates = [str(i) for i in dates]
|
dates = [str(i) for i in dates]
|
||||||
|
|
||||||
|
newest_file = watch['history'][dates[0]]
|
||||||
left_file_contents = right_file_contents = ""
|
with open(newest_file, 'r') as f:
|
||||||
l_file = watch['history'][str(dates[1])]
|
newest_version_file_contents = f.read()
|
||||||
with open(l_file, 'r') as f:
|
|
||||||
left_file_contents = f.read()
|
|
||||||
|
|
||||||
previous_version = request.args.get('previous_version')
|
previous_version = request.args.get('previous_version')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r_file = watch['history'][str(previous_version)]
|
previous_file = watch['history'][previous_version]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# Not present, use a default value
|
# Not present, use a default value, the second one in the sorted list.
|
||||||
r_file = watch['history'][dates[0]]
|
previous_file = watch['history'][dates[1]]
|
||||||
|
|
||||||
with open(r_file, 'r') as f:
|
with open(previous_file, 'r') as f:
|
||||||
right_file_contents = f.read()
|
previous_version_file_contents = f.read()
|
||||||
|
|
||||||
|
output = render_template("diff.html", watch_a=watch,
|
||||||
|
messages=messages,
|
||||||
|
newest=newest_version_file_contents,
|
||||||
|
previous=previous_version_file_contents,
|
||||||
|
extra_stylesheets=extra_stylesheets,
|
||||||
|
versions=dates[1:],
|
||||||
|
current_previous_version=str(previous_version),
|
||||||
|
current_diff_url=watch['url'])
|
||||||
|
|
||||||
#print (dates, l_file, r_file)
|
|
||||||
output = render_template("diff.html", watch_a=watch, messages=messages, left=left_file_contents,
|
|
||||||
right=right_file_contents, extra_stylesheets=extra_stylesheets, versions=dates[:-1],
|
|
||||||
current_previous_version=str(previous_version), current_diff_url=watch['url'])
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
@app.route("/favicon.ico", methods=['GET'])
|
@app.route("/favicon.ico", methods=['GET'])
|
||||||
|
|
|
@ -38,8 +38,8 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<!-- just proof of concept copied straight from github.com/kpdecker/jsdiff -->
|
<!-- just proof of concept copied straight from github.com/kpdecker/jsdiff -->
|
||||||
<td id="a" style="display: none;">{{left}}</td>
|
<td id="a" style="display: none;">{{previous}}</td>
|
||||||
<td id="b" style="display: none;">{{right}}</td>
|
<td id="b" style="display: none;">{{newest}}</td>
|
||||||
<td>
|
<td>
|
||||||
<span id="result"></span>
|
<span id="result"></span>
|
||||||
</td>
|
</td>
|
||||||
|
|
Ładowanie…
Reference in New Issue