pull/1/head
Leigh Morresi 3 years ago
parent 604d0e0317
commit 44f0639dfe

1
.gitignore vendored

@ -1,3 +1,4 @@
__pycache__
.idea
*.pyc
datastore/url-watches.json

@ -9,14 +9,13 @@ import os
import getopt
import sys
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
import store
datastore = store.ChangeDetectionStore()
messages = []
app = Flask(__name__, static_url_path='/static')
app.config['STATIC_RESOURCES'] = "/app/static"
@ -28,7 +27,12 @@ app.config['TEMPLATES_AUTO_RELOAD'] = True
@app.route("/", methods=['GET'])
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'])
@ -39,6 +43,19 @@ def static_content(group, filename):
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):
ssl_mode = False

@ -6,19 +6,13 @@ python-engineio
six==1.10.0
yarl
flask
gevent-websocket
eventlet
requests
validators
# Actual connecting to services
pytz
phpserialize==1.3.0
redis>=2.6.2
pymysql==0.8
bleach==3.2.1
html5lib==0.9999999 # via bleach
flask_socketio~=5.0
# @notes
# - Dont install socketio, it interferes with flask_socketio

@ -17,7 +17,9 @@ a.github-link {
}
section.content {
padding-top: 3em;
flex-direction: column;
display: flex;
align-items: center;
justify-content: center;

@ -1,8 +1,10 @@
import json
import uuid
import validators
# 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 :)
# https://stackoverflow.com/questions/6190468/how-to-trigger-function-on-value-change
class ChangeDetectionStore:
def __init__(self):
@ -22,6 +24,7 @@ class ChangeDetectionStore:
self.data['watching'].append({
'url': 'https://changedetection.io',
'tag': 'general',
'last_checked': 0,
'uuid': str(uuid.uuid4())
})
@ -29,6 +32,16 @@ class ChangeDetectionStore:
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):
with open('/datastore/url-watches.json', 'w') as json_file:

@ -34,12 +34,17 @@
<header>
{% block header %}{% endblock %}
</header>
<!--
{% for message in get_flashed_messages() %}
<div class="flash">{{ message }}</div>
{% endfor %}
-->
{% block content %}{% endblock %}
<div class="messages">
{% for message in messages %}
<div class="flash-message {{ message['class'] }}">{{ message['message'] }}</div>
{% endfor %}
</div>
{% block content %}
{% endblock %}
</section>
</body>
</html>

@ -3,16 +3,16 @@
{% block content %}
<div class="box">
<form class="pure-form">
<form class="pure-form" action="/api/add" method="POST">
<fieldset>
<legend>Add new change detection watch</legend>
<input type="url" placeholder="https://..." />
<input type="text" placeholder="tag" size="10" />
<input type="url" placeholder="https://..." name="url"/>
<input type="text" placeholder="tag" size="10" name="tag"/>
<button type="submit" class="pure-button pure-button-primary">Save</button>
</fieldset>
</form>
<table class="pure-table">
<table class="pure-table pure-table-striped">
<thead>
<tr>
<th>#</th>
@ -26,8 +26,8 @@
{% for watch in watches %}
<tr class="pure-table-odd">
<td>1</td>
<tr class="{{ loop.cycle('pure-table-odd', 'pure-table-even') }}">
<td>{{ loop.index }}</td>
<td>{{ watch.url }}</td>
<td>2021/2/2 14:00:00</td>
<td>No Change</td>

@ -1 +0,0 @@
{"watching": [{"url": "https://changedetection.io", "tag": "general", "uuid": "3ba44e22-af8b-4dfd-8227-f9be55bd5788"}]}
Loading…
Cancel
Save