You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
changedetection.io/backend/store.py

37 lines
1.1 KiB

4 years ago
import json
import uuid
# 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 :)
class ChangeDetectionStore:
def __init__(self):
try:
with open('/datastore/url-watches.json') as json_file:
self.data = json.load(json_file)
for p in self.data['watching']:
print('url: ' + p['url'])
print('')
# First time ran, doesnt exist.
except (FileNotFoundError, json.decoder.JSONDecodeError):
print ("Resetting JSON store")
self.data = {}
self.data['watching'] = []
self.data['watching'].append({
'url': 'https://changedetection.io',
'tag': 'general',
'uuid': str(uuid.uuid4())
})
with open('/datastore/url-watches.json', 'w') as json_file:
json.dump(self.data, json_file)
def sync_to_json(self):
with open('/datastore/url-watches.json', 'w') as json_file:
json.dump(self.data, json_file)
# body of the constructor