mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2025-10-30 22:27:52 +00:00
Compare commits
2 Commits
fix-mixed-
...
diff-strea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14d88c249e | ||
|
|
0fa443c3f2 |
@@ -99,6 +99,8 @@ def changedetection_app(config=None, datastore_o=None):
|
||||
global messages
|
||||
|
||||
limit_tag = request.args.get('tag')
|
||||
rss = request.args.get('rss')
|
||||
mode = request.args.get('mode')
|
||||
|
||||
# Sort by last_changed and add the uuid which is usually the key..
|
||||
sorted_watches = []
|
||||
@@ -119,7 +121,63 @@ def changedetection_app(config=None, datastore_o=None):
|
||||
sorted_watches.sort(key=lambda x: x['last_changed'], reverse=True)
|
||||
|
||||
existing_tags = datastore.get_all_tags()
|
||||
rss = request.args.get('rss')
|
||||
|
||||
if mode == 'stream':
|
||||
import difflib
|
||||
|
||||
import pprint
|
||||
streams = []
|
||||
|
||||
extra_stylesheets = ['/static/css/diff.css']
|
||||
for watch in sorted_watches:
|
||||
if not watch['viewed']:
|
||||
|
||||
# get last two date keys
|
||||
dates = list(watch['history'].keys())
|
||||
# Convert to int, sort and back to str again
|
||||
dates = [int(i) for i in dates]
|
||||
dates.sort(reverse=True)
|
||||
dates = [str(i) for i in dates]
|
||||
print ("OK", watch['uuid'])
|
||||
|
||||
if len(dates) < 2:
|
||||
print ("Skipping", watch['url'])
|
||||
continue
|
||||
else:
|
||||
try:
|
||||
path = datastore.data['watching'][watch['uuid']]['history'][str(dates[1])]
|
||||
with open(path,
|
||||
encoding='utf-8') as file:
|
||||
txt1=[line.rstrip() for line in file.readlines()]
|
||||
|
||||
path = datastore.data['watching'][watch['uuid']]['history'][str(dates[0])]
|
||||
with open(path,
|
||||
encoding='utf-8') as file:
|
||||
txt2 = [line.rstrip() for line in file.readlines()]
|
||||
except FileNotFoundError:
|
||||
print ("Skipping", watch['url'])
|
||||
continue
|
||||
|
||||
df = list(difflib.unified_diff(txt1, txt2,n=1))
|
||||
diff_entry=[]
|
||||
for line in df:
|
||||
if line[0] == '-' or line[0] == '+':
|
||||
diff_entry.append(line)
|
||||
|
||||
|
||||
# pprint(df)
|
||||
#s = pprint.pformat(df)
|
||||
streams.append(diff_entry)
|
||||
|
||||
|
||||
print ("###########", len(streams))
|
||||
|
||||
output = render_template("watch-diff-stream.html",
|
||||
streams=streams,
|
||||
extra_stylesheets=extra_stylesheets
|
||||
)
|
||||
return output
|
||||
|
||||
|
||||
if rss:
|
||||
fg = FeedGenerator()
|
||||
@@ -143,7 +201,8 @@ def changedetection_app(config=None, datastore_o=None):
|
||||
return response
|
||||
|
||||
else:
|
||||
output = render_template("watch-overview.html",
|
||||
#table = render_template('watch-table.html', watches=sorted_watches)
|
||||
output = render_template("watch-table.html",
|
||||
watches=sorted_watches,
|
||||
messages=messages,
|
||||
tags=existing_tags,
|
||||
@@ -589,15 +648,16 @@ def ticker_thread_check_time_launch_checks():
|
||||
running_update_threads.append(new_worker)
|
||||
new_worker.start()
|
||||
|
||||
# Every minute check for new UUIDs to follow up on
|
||||
minutes = datastore.data['settings']['requests']['minutes_between_check']
|
||||
|
||||
while not app.config.exit.is_set():
|
||||
running_uuids = []
|
||||
for t in running_update_threads:
|
||||
running_uuids.append(t.current_uuid)
|
||||
|
||||
# Look at the dataset, find a stale watch to process
|
||||
|
||||
# Every minute check for new UUIDs to follow up on, should be inside the loop incase it changes.
|
||||
minutes = datastore.data['settings']['requests']['minutes_between_check']
|
||||
|
||||
threshold = time.time() - (minutes * 60)
|
||||
for uuid, watch in datastore.data['watching'].items():
|
||||
if watch['last_checked'] <= threshold:
|
||||
|
||||
@@ -266,3 +266,8 @@ footer {
|
||||
#new-version-text a{
|
||||
color: #e07171;
|
||||
}
|
||||
|
||||
#diff-stream {
|
||||
font-size: 10px;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
@@ -228,6 +228,12 @@ class ChangeDetectionStore:
|
||||
# result_obj from fetch_site_status.run()
|
||||
def save_history_text(self, uuid, result_obj, contents):
|
||||
|
||||
output_path = "{}/{}".format(self.datastore_path, uuid)
|
||||
try:
|
||||
os.mkdir(output_path)
|
||||
except FileExistsError:
|
||||
pass
|
||||
|
||||
output_path = "{}/{}".format(self.datastore_path, uuid)
|
||||
fname = "{}/{}-{}.stripped.txt".format(output_path, result_obj['previous_md5'], str(time.time()))
|
||||
with open(fname, 'w') as f:
|
||||
|
||||
12
backend/templates/watch-diff-stream.html
Normal file
12
backend/templates/watch-diff-stream.html
Normal file
@@ -0,0 +1,12 @@
|
||||
{% extends 'watch-overview.html' %}
|
||||
{% block innercontent %}
|
||||
Entries: {{ streams|length }}
|
||||
|
||||
<div id="diff-stream" class="edit-form">
|
||||
{% for item in streams %}
|
||||
{{ loop.index }}
|
||||
{% for diff in item %}{% if diff[0] =='+' %}<ins>{{ diff }}</ins>{% endif %}{% if diff[0] =='-' %}<del>{{ diff }}</del>{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -24,67 +24,9 @@
|
||||
</div>
|
||||
|
||||
<div id="watch-table-wrapper">
|
||||
<table class="pure-table pure-table-striped watch-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th></th>
|
||||
<th>Last Checked</th>
|
||||
<th>Last Changed</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% block innercontent %}
|
||||
|
||||
|
||||
{% for watch in watches %}
|
||||
<tr id="{{ watch.uuid }}"
|
||||
class="{{ loop.cycle('pure-table-odd', 'pure-table-even') }}
|
||||
{% if watch.last_error is defined and watch.last_error != False %}error{% endif %}
|
||||
{% if watch.newest_history_key| int > watch.last_viewed| int %}unviewed{% endif %}">
|
||||
<td>{{ loop.index }}</td>
|
||||
<td class="title-col">{{watch.title if watch.title is not none else watch.url}}
|
||||
<a class="external" target=_blank href="{{ watch.url }}"></a>
|
||||
{% if watch.last_error is defined and watch.last_error != False %}
|
||||
<div class="fetch-error">{{ watch.last_error }}</div>
|
||||
{% endif %}
|
||||
{% if not active_tag %}
|
||||
<span class="watch-tag-list">{{ watch.tag}}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{watch|format_last_checked_time}}</td>
|
||||
<td>{% if watch.history|length >= 2 and watch.last_changed %}
|
||||
{{watch.last_changed|format_timestamp_timeago}}
|
||||
{% else %}
|
||||
Not yet
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<a href="/api/checknow?uuid={{ watch.uuid}}{% if request.args.get('tag') %}&tag={{request.args.get('tag')}}{% endif %}"
|
||||
class="pure-button button-small pure-button-primary">Recheck</a>
|
||||
<a href="/edit/{{ watch.uuid}}" class="pure-button button-small pure-button-primary">Edit</a>
|
||||
{% if watch.history|length >= 2 %}
|
||||
<a href="/diff/{{ watch.uuid}}" class="pure-button button-small pure-button-primary">Diff</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<ul id="post-list-buttons">
|
||||
{% if has_unviewed %}
|
||||
<li>
|
||||
<a href="/api/mark-all-viewed" class="pure-button button-tag ">Mark all viewed</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li>
|
||||
<a href="/api/checknow{% if active_tag%}?tag={{active_tag}}{%endif%}" class="pure-button button-tag ">Recheck
|
||||
all {% if active_tag%}in "{{active_tag}}"{%endif%}</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url_for('index', tag=active_tag , rss=true)}}"><img id="feed-icon" src="/static/images/Generic_Feed-icon.svg" height="15px"></a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
64
backend/templates/watch-table.html
Normal file
64
backend/templates/watch-table.html
Normal file
@@ -0,0 +1,64 @@
|
||||
{% extends 'watch-overview.html' %}
|
||||
{% block innercontent %}
|
||||
<table class="pure-table pure-table-striped watch-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th></th>
|
||||
<th>Last Checked</th>
|
||||
<th>Last Changed</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
|
||||
{% for watch in watches %}
|
||||
<tr id="{{ watch.uuid }}"
|
||||
class="{{ loop.cycle('pure-table-odd', 'pure-table-even') }}
|
||||
{% if watch.last_error is defined and watch.last_error != False %}error{% endif %}
|
||||
{% if watch.newest_history_key| int > watch.last_viewed| int %}unviewed{% endif %}">
|
||||
<td>{{ loop.index }}</td>
|
||||
<td class="title-col">{{watch.title if watch.title is not none else watch.url}}
|
||||
<a class="external" target=_blank href="{{ watch.url }}"></a>
|
||||
{% if watch.last_error is defined and watch.last_error != False %}
|
||||
<div class="fetch-error">{{ watch.last_error }}</div>
|
||||
{% endif %}
|
||||
{% if not active_tag %}
|
||||
<span class="watch-tag-list">{{ watch.tag}}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{watch|format_last_checked_time}}</td>
|
||||
<td>{% if watch.history|length >= 2 and watch.last_changed %}
|
||||
{{watch.last_changed|format_timestamp_timeago}}
|
||||
{% else %}
|
||||
Not yet
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<a href="/api/checknow?uuid={{ watch.uuid}}{% if request.args.get('tag') %}&tag={{request.args.get('tag')}}{% endif %}"
|
||||
class="pure-button button-small pure-button-primary">Recheck</a>
|
||||
<a href="/edit/{{ watch.uuid}}" class="pure-button button-small pure-button-primary">Edit</a>
|
||||
{% if watch.history|length >= 2 %}
|
||||
<a href="/diff/{{ watch.uuid}}" class="pure-button button-small pure-button-primary">Diff</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<ul id="post-list-buttons">
|
||||
{% if has_unviewed %}
|
||||
<li>
|
||||
<a href="/api/mark-all-viewed" class="pure-button button-tag ">Mark all viewed</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li>
|
||||
<a href="/api/checknow{% if active_tag%}?tag={{active_tag}}{%endif%}" class="pure-button button-tag ">Recheck
|
||||
all {% if active_tag%}in "{{active_tag}}"{%endif%}</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url_for('index', tag=active_tag , rss=true)}}"><img id="feed-icon" src="/static/images/Generic_Feed-icon.svg" height="15px"></a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user