kopia lustrzana https://github.com/dgtlmoon/changedetection.io
pull/1/head
rodzic
604d0e0317
commit
44f0639dfe
|
@ -1,3 +1,4 @@
|
||||||
__pycache__
|
__pycache__
|
||||||
.idea
|
.idea
|
||||||
*.pyc
|
*.pyc
|
||||||
|
datastore/url-watches.json
|
||||||
|
|
|
@ -9,14 +9,13 @@ import os
|
||||||
import getopt
|
import getopt
|
||||||
import sys
|
import sys
|
||||||
import datetime
|
import datetime
|
||||||
from flask import Flask, render_template, request, send_file, send_from_directory, safe_join, abort
|
from flask import Flask, render_template, request, send_file, send_from_directory, safe_join, abort, redirect, url_for
|
||||||
|
|
||||||
# Local
|
# Local
|
||||||
import store
|
import store
|
||||||
|
|
||||||
|
|
||||||
datastore = store.ChangeDetectionStore()
|
datastore = store.ChangeDetectionStore()
|
||||||
|
messages = []
|
||||||
app = Flask(__name__, static_url_path='/static')
|
app = Flask(__name__, static_url_path='/static')
|
||||||
app.config['STATIC_RESOURCES'] = "/app/static"
|
app.config['STATIC_RESOURCES'] = "/app/static"
|
||||||
|
|
||||||
|
@ -28,7 +27,12 @@ app.config['TEMPLATES_AUTO_RELOAD'] = True
|
||||||
|
|
||||||
@app.route("/", methods=['GET'])
|
@app.route("/", methods=['GET'])
|
||||||
def main_page():
|
def main_page():
|
||||||
return render_template("watch-overview.html", watches=datastore.data['watching'])
|
global messages
|
||||||
|
|
||||||
|
# Show messages but once.
|
||||||
|
output = render_template("watch-overview.html", watches=datastore.data['watching'], messages=messages)
|
||||||
|
messages = []
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
@app.route("/static/<string:group>/<string:filename>", methods=['GET'])
|
@app.route("/static/<string:group>/<string:filename>", methods=['GET'])
|
||||||
|
@ -39,6 +43,19 @@ def static_content(group, filename):
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/api/add", methods=['POST'])
|
||||||
|
def api_watch_add():
|
||||||
|
global messages
|
||||||
|
|
||||||
|
#@todo add_watch should throw a custom Exception for validation etc
|
||||||
|
datastore.add_watch(url=request.form.get('url'), tag=request.form.get('tag'))
|
||||||
|
messages.append({'class':'ok', 'message': 'Saved'})
|
||||||
|
|
||||||
|
return redirect(url_for('main_page'))
|
||||||
|
# datastore.add_watch
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
ssl_mode = False
|
ssl_mode = False
|
||||||
|
|
|
@ -6,19 +6,13 @@ python-engineio
|
||||||
six==1.10.0
|
six==1.10.0
|
||||||
yarl
|
yarl
|
||||||
flask
|
flask
|
||||||
gevent-websocket
|
|
||||||
eventlet
|
eventlet
|
||||||
requests
|
requests
|
||||||
|
validators
|
||||||
|
|
||||||
# Actual connecting to services
|
|
||||||
pytz
|
|
||||||
phpserialize==1.3.0
|
|
||||||
redis>=2.6.2
|
|
||||||
pymysql==0.8
|
|
||||||
bleach==3.2.1
|
bleach==3.2.1
|
||||||
html5lib==0.9999999 # via bleach
|
html5lib==0.9999999 # via bleach
|
||||||
|
|
||||||
flask_socketio~=5.0
|
|
||||||
|
|
||||||
# @notes
|
# @notes
|
||||||
# - Dont install socketio, it interferes with flask_socketio
|
# - Dont install socketio, it interferes with flask_socketio
|
||||||
|
|
|
@ -17,7 +17,9 @@ a.github-link {
|
||||||
}
|
}
|
||||||
|
|
||||||
section.content {
|
section.content {
|
||||||
|
|
||||||
padding-top: 3em;
|
padding-top: 3em;
|
||||||
|
flex-direction: column;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
import validators
|
||||||
|
|
||||||
# Is there an existing library to ensure some data store (JSON etc) is in sync with CRUD methods?
|
# Is there an existing library to ensure some data store (JSON etc) is in sync with CRUD methods?
|
||||||
# Open a github issue if you know something :)
|
# Open a github issue if you know something :)
|
||||||
|
# https://stackoverflow.com/questions/6190468/how-to-trigger-function-on-value-change
|
||||||
class ChangeDetectionStore:
|
class ChangeDetectionStore:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -22,6 +24,7 @@ class ChangeDetectionStore:
|
||||||
self.data['watching'].append({
|
self.data['watching'].append({
|
||||||
'url': 'https://changedetection.io',
|
'url': 'https://changedetection.io',
|
||||||
'tag': 'general',
|
'tag': 'general',
|
||||||
|
'last_checked': 0,
|
||||||
'uuid': str(uuid.uuid4())
|
'uuid': str(uuid.uuid4())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -29,6 +32,16 @@ class ChangeDetectionStore:
|
||||||
json.dump(self.data, json_file)
|
json.dump(self.data, json_file)
|
||||||
|
|
||||||
|
|
||||||
|
def add_watch(self, url, tag):
|
||||||
|
validators.url(url)
|
||||||
|
|
||||||
|
self.data['watching'].append({
|
||||||
|
'url': url,
|
||||||
|
'tag': tag,
|
||||||
|
'uuid': str(uuid.uuid4())
|
||||||
|
})
|
||||||
|
self.sync_to_json()
|
||||||
|
# @todo throw custom exception
|
||||||
|
|
||||||
def sync_to_json(self):
|
def sync_to_json(self):
|
||||||
with open('/datastore/url-watches.json', 'w') as json_file:
|
with open('/datastore/url-watches.json', 'w') as json_file:
|
||||||
|
|
|
@ -34,12 +34,17 @@
|
||||||
<header>
|
<header>
|
||||||
{% block header %}{% endblock %}
|
{% block header %}{% endblock %}
|
||||||
</header>
|
</header>
|
||||||
<!--
|
|
||||||
{% for message in get_flashed_messages() %}
|
<div class="messages">
|
||||||
<div class="flash">{{ message }}</div>
|
{% for message in messages %}
|
||||||
|
<div class="flash-message {{ message['class'] }}">{{ message['message'] }}</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
-->
|
</div>
|
||||||
{% block content %}{% endblock %}
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
</section>
|
</section>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -3,16 +3,16 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="box">
|
<div class="box">
|
||||||
|
|
||||||
<form class="pure-form">
|
<form class="pure-form" action="/api/add" method="POST">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Add new change detection watch</legend>
|
<legend>Add new change detection watch</legend>
|
||||||
<input type="url" placeholder="https://..." />
|
<input type="url" placeholder="https://..." name="url"/>
|
||||||
<input type="text" placeholder="tag" size="10" />
|
<input type="text" placeholder="tag" size="10" name="tag"/>
|
||||||
<button type="submit" class="pure-button pure-button-primary">Save</button>
|
<button type="submit" class="pure-button pure-button-primary">Save</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<table class="pure-table">
|
<table class="pure-table pure-table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
|
@ -26,8 +26,8 @@
|
||||||
|
|
||||||
|
|
||||||
{% for watch in watches %}
|
{% for watch in watches %}
|
||||||
<tr class="pure-table-odd">
|
<tr class="{{ loop.cycle('pure-table-odd', 'pure-table-even') }}">
|
||||||
<td>1</td>
|
<td>{{ loop.index }}</td>
|
||||||
<td>{{ watch.url }}</td>
|
<td>{{ watch.url }}</td>
|
||||||
<td>2021/2/2 14:00:00</td>
|
<td>2021/2/2 14:00:00</td>
|
||||||
<td>No Change</td>
|
<td>No Change</td>
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
{"watching": [{"url": "https://changedetection.io", "tag": "general", "uuid": "3ba44e22-af8b-4dfd-8227-f9be55bd5788"}]}
|
|
Ładowanie…
Reference in New Issue