This commit is contained in:
Leigh Morresi
2021-01-27 13:17:35 +01:00
parent 604d0e0317
commit 44f0639dfe
8 changed files with 57 additions and 26 deletions

View File

@@ -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: