pull/15/head
Leigh Morresi 4 years ago
parent 0ec9edb971
commit 47fcb8b4f8

@ -151,6 +151,34 @@ def changedetection_app(config=None, datastore_o=None):
return render_template("scrub.html") return render_template("scrub.html")
# If they edited an existing watch, we need to know to reset the current/previous md5 to include
# the excluded text.
def get_current_checksum_include_ignore_text(uuid):
import hashlib
from backend import fetch_site_status
# Get the most recent one
newest_history_key = datastore.get_val(uuid, 'newest_history_key')
# 0 means that theres only one, so that there should be no 'unviewed' history availabe
if newest_history_key == 0:
newest_history_key = list(datastore.data['watching'][uuid]['history'].keys())[0]
if newest_history_key:
with open(datastore.data['watching'][uuid]['history'][newest_history_key],
encoding='utf-8') as file:
raw_content = file.read()
handler = fetch_site_status.perform_site_check(datastore=datastore)
stripped_content = handler.strip_ignore_text(raw_content,
datastore.data['watching'][uuid]['ignore_text'])
checksum = hashlib.md5(stripped_content).hexdigest()
return checksum
return datastore.data['watching'][uuid]['previous_md5']
@app.route("/edit/<string:uuid>", methods=['GET', 'POST']) @app.route("/edit/<string:uuid>", methods=['GET', 'POST'])
def edit_page(uuid): def edit_page(uuid):
global messages global messages
@ -183,16 +211,19 @@ def changedetection_app(config=None, datastore_o=None):
# Ignore text # Ignore text
form_ignore_text = request.form.get('ignore-text').strip() form_ignore_text = request.form.get('ignore-text').strip()
ignore_text = [] ignore_text = []
if form_ignore_text: if len(form_ignore_text):
for text in form_ignore_text.split("\n"): for text in form_ignore_text.split("\n"):
text = text.strip() text = text.strip()
if len(text): if len(text):
ignore_text.append(text) ignore_text.append(text)
datastore.data['watching'][uuid]['ignore_text'] = ignore_text
# Reset the previous_md5 so we process a new snapshot including stripping ignore text. # Reset the previous_md5 so we process a new snapshot including stripping ignore text.
update_obj['previous_md5'] = "reprocess previous" if len( datastore.data['watching'][uuid]['history']):
update_obj['previous_md5'] = get_current_checksum_include_ignore_text(uuid=uuid)
update_obj['ignore_text'] = ignore_text
validators.url(url) # @todo switch to prop/attr/observer validators.url(url) # @todo switch to prop/attr/observer
datastore.data['watching'][uuid].update(update_obj) datastore.data['watching'][uuid].update(update_obj)

@ -27,6 +27,8 @@ class perform_site_check():
return "\n".encode('utf8').join(output) return "\n".encode('utf8').join(output)
def run(self, uuid): def run(self, uuid):
timestamp = int(time.time()) # used for storage etc too timestamp = int(time.time()) # used for storage etc too
stripped_text_from_html = False stripped_text_from_html = False
@ -98,27 +100,10 @@ class perform_site_check():
content = self.strip_ignore_text(stripped_text_from_html, content = self.strip_ignore_text(stripped_text_from_html,
self.datastore.data['watching'][uuid]['ignore_text']) self.datastore.data['watching'][uuid]['ignore_text'])
else: else:
content = stripped_text_from_html content = stripped_text_from_html.encode('utf8')
fetched_md5 = hashlib.md5(content).hexdigest() fetched_md5 = hashlib.md5(content).hexdigest()
# If they edited an existing watch, we need to know to reset the current/previous md5 to include
# the excluded text.
if self.datastore.data['watching'][uuid]['previous_md5'] == "reprocess previous":
# Get the most recent one
newest_history_key = self.datastore.get_newest_history_key(uuid)
if newest_history_key:
with open(self.datastore.data['watching'][uuid]['history'][newest_history_key],
encoding='utf-8') as file:
raw_content = file.read()
stripped_content = self.strip_ignore_text(raw_content,
self.datastore.data['watching'][uuid]['ignore_text'])
checksum = hashlib.md5(stripped_content).hexdigest()
self.datastore.data['watching'][uuid]['previous_md5'] = checksum
# could be None or False depending on JSON type # could be None or False depending on JSON type
if self.datastore.data['watching'][uuid]['previous_md5'] != fetched_md5: if self.datastore.data['watching'][uuid]['previous_md5'] != fetched_md5:
changed_detected = True changed_detected = True

@ -118,5 +118,6 @@ def test_check_basic_change_detection_functionality(client, live_server):
res = client.get(url_for("index")) res = client.get(url_for("index"))
assert b'unviewed' in res.data assert b'unviewed' in res.data
# Cleanup everything
res = client.get(url_for("api_delete", uuid="all"), follow_redirects=True) res = client.get(url_for("api_delete", uuid="all"), follow_redirects=True)
assert b'Deleted' in res.data assert b'Deleted' in res.data

Loading…
Cancel
Save