kopia lustrzana https://github.com/dgtlmoon/changedetection.io
Code tidy/lint
rodzic
e0578acca2
commit
fb38b06eae
|
@ -21,7 +21,7 @@ from threading import Event
|
||||||
|
|
||||||
import queue
|
import queue
|
||||||
|
|
||||||
from flask import Flask, render_template, request, send_file, send_from_directory, abort, redirect, url_for
|
from flask import Flask, render_template, request, send_file, send_from_directory, abort, redirect, url_for
|
||||||
|
|
||||||
from feedgen.feed import FeedGenerator
|
from feedgen.feed import FeedGenerator
|
||||||
from flask import make_response
|
from flask import make_response
|
||||||
|
@ -87,8 +87,6 @@ def changedetection_app(config=None, datastore_o=None):
|
||||||
app.config.update(dict(DEBUG=True))
|
app.config.update(dict(DEBUG=True))
|
||||||
app.config.update(config or {})
|
app.config.update(config or {})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Setup cors headers to allow all domains
|
# Setup cors headers to allow all domains
|
||||||
# https://flask-cors.readthedocs.io/en/latest/
|
# https://flask-cors.readthedocs.io/en/latest/
|
||||||
# CORS(app)
|
# CORS(app)
|
||||||
|
@ -96,7 +94,6 @@ def changedetection_app(config=None, datastore_o=None):
|
||||||
# https://github.com/pallets/flask/blob/93dd1709d05a1cf0e886df6223377bdab3b077fb/examples/tutorial/flaskr/__init__.py#L39
|
# https://github.com/pallets/flask/blob/93dd1709d05a1cf0e886df6223377bdab3b077fb/examples/tutorial/flaskr/__init__.py#L39
|
||||||
# You can divide up the stuff like this
|
# You can divide up the stuff like this
|
||||||
|
|
||||||
|
|
||||||
@app.route("/", methods=['GET'])
|
@app.route("/", methods=['GET'])
|
||||||
def index():
|
def index():
|
||||||
global messages
|
global messages
|
||||||
|
@ -156,7 +153,6 @@ def changedetection_app(config=None, datastore_o=None):
|
||||||
# Show messages but once.
|
# Show messages but once.
|
||||||
messages = []
|
messages = []
|
||||||
|
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
@app.route("/scrub", methods=['GET', 'POST'])
|
@app.route("/scrub", methods=['GET', 'POST'])
|
||||||
|
@ -209,7 +205,7 @@ def changedetection_app(config=None, datastore_o=None):
|
||||||
|
|
||||||
handler = fetch_site_status.perform_site_check(datastore=datastore)
|
handler = fetch_site_status.perform_site_check(datastore=datastore)
|
||||||
stripped_content = handler.strip_ignore_text(raw_content,
|
stripped_content = handler.strip_ignore_text(raw_content,
|
||||||
datastore.data['watching'][uuid]['ignore_text'])
|
datastore.data['watching'][uuid]['ignore_text'])
|
||||||
|
|
||||||
checksum = hashlib.md5(stripped_content).hexdigest()
|
checksum = hashlib.md5(stripped_content).hexdigest()
|
||||||
return checksum
|
return checksum
|
||||||
|
@ -257,11 +253,9 @@ def changedetection_app(config=None, datastore_o=None):
|
||||||
datastore.data['watching'][uuid]['ignore_text'] = ignore_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.
|
||||||
if len( datastore.data['watching'][uuid]['history']):
|
if len(datastore.data['watching'][uuid]['history']):
|
||||||
update_obj['previous_md5'] = get_current_checksum_include_ignore_text(uuid=uuid)
|
update_obj['previous_md5'] = get_current_checksum_include_ignore_text(uuid=uuid)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
datastore.needs_write = True
|
datastore.needs_write = True
|
||||||
|
@ -325,7 +319,7 @@ def changedetection_app(config=None, datastore_o=None):
|
||||||
|
|
||||||
if len(remaining_urls) == 0:
|
if len(remaining_urls) == 0:
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
#@todo repair
|
# @todo repair
|
||||||
else:
|
else:
|
||||||
output = render_template("import.html",
|
output = render_template("import.html",
|
||||||
messages=messages,
|
messages=messages,
|
||||||
|
@ -352,7 +346,7 @@ def changedetection_app(config=None, datastore_o=None):
|
||||||
|
|
||||||
# More for testing, possible to return the first/only
|
# More for testing, possible to return the first/only
|
||||||
if uuid == 'first':
|
if uuid == 'first':
|
||||||
uuid= list(datastore.data['watching'].keys()).pop()
|
uuid = list(datastore.data['watching'].keys()).pop()
|
||||||
|
|
||||||
extra_stylesheets = ['/static/css/diff.css']
|
extra_stylesheets = ['/static/css/diff.css']
|
||||||
try:
|
try:
|
||||||
|
@ -367,9 +361,9 @@ def changedetection_app(config=None, datastore_o=None):
|
||||||
dates.sort(reverse=True)
|
dates.sort(reverse=True)
|
||||||
dates = [str(i) for i in dates]
|
dates = [str(i) for i in dates]
|
||||||
|
|
||||||
|
|
||||||
if len(dates) < 2:
|
if len(dates) < 2:
|
||||||
messages.append({'class': 'error', 'message': "Not enough saved change detection snapshots to produce a report."})
|
messages.append(
|
||||||
|
{'class': 'error', 'message': "Not enough saved change detection snapshots to produce a report."})
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
# Save the current newest history as the most recently viewed
|
# Save the current newest history as the most recently viewed
|
||||||
|
@ -531,6 +525,7 @@ def check_for_new_version():
|
||||||
|
|
||||||
app.config.exit.wait(10)
|
app.config.exit.wait(10)
|
||||||
|
|
||||||
|
|
||||||
# Requests for checking on the site use a pool of thread Workers managed by a Queue.
|
# Requests for checking on the site use a pool of thread Workers managed by a Queue.
|
||||||
class Worker(threading.Thread):
|
class Worker(threading.Thread):
|
||||||
current_uuid = None
|
current_uuid = None
|
||||||
|
@ -569,17 +564,14 @@ class Worker(threading.Thread):
|
||||||
# A change was detected
|
# A change was detected
|
||||||
datastore.save_history_text(uuid=uuid, contents=contents, result_obj=result)
|
datastore.save_history_text(uuid=uuid, contents=contents, result_obj=result)
|
||||||
|
|
||||||
|
|
||||||
self.current_uuid = None # Done
|
self.current_uuid = None # Done
|
||||||
self.q.task_done()
|
self.q.task_done()
|
||||||
|
|
||||||
app.config.exit.wait(1)
|
app.config.exit.wait(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Thread runner to check every minute, look for new watches to feed into the Queue.
|
# Thread runner to check every minute, look for new watches to feed into the Queue.
|
||||||
def ticker_thread_check_time_launch_checks():
|
def ticker_thread_check_time_launch_checks():
|
||||||
|
|
||||||
# Spin up Workers.
|
# Spin up Workers.
|
||||||
for _ in range(datastore.data['settings']['requests']['workers']):
|
for _ in range(datastore.data['settings']['requests']['workers']):
|
||||||
new_worker = Worker(update_q)
|
new_worker = Worker(update_q)
|
||||||
|
|
Ładowanie…
Reference in New Issue