mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2025-12-01 05:43:23 +00:00
Compare commits
8 Commits
0.39.20.2
...
push-and-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13576d081b | ||
|
|
b6373779d0 | ||
|
|
4cbcc59461 | ||
|
|
4be0260381 | ||
|
|
957a3c1c16 | ||
|
|
85897e0bf9 | ||
|
|
63095f70ea | ||
|
|
8d5b0b5576 |
3
.github/workflows/test-container-build.yml
vendored
3
.github/workflows/test-container-build.yml
vendored
@@ -1,8 +1,7 @@
|
||||
name: ChangeDetection.io Container Build Test
|
||||
|
||||
# Triggers the workflow on push or pull request events
|
||||
on:
|
||||
push:
|
||||
on: [push, pull_request]
|
||||
paths:
|
||||
- requirements.txt
|
||||
- Dockerfile
|
||||
|
||||
@@ -2,6 +2,7 @@ recursive-include changedetectionio/api *
|
||||
recursive-include changedetectionio/templates *
|
||||
recursive-include changedetectionio/static *
|
||||
recursive-include changedetectionio/model *
|
||||
recursive-include changedetectionio/tests *
|
||||
include changedetection.py
|
||||
global-exclude *.pyc
|
||||
global-exclude node_modules
|
||||
|
||||
44
README.md
44
README.md
@@ -161,50 +161,14 @@ This will re-parse the JSON and apply formatting to the text, making it super ea
|
||||
|
||||
### JSONPath or jq?
|
||||
|
||||
For more complex parsing, filtering, and modifying of JSON data, jq is recommended due to the built-in operators and functions. Refer to the [documentation](https://stedolan.github.io/jq/manual/) for more information on jq.
|
||||
For more complex parsing, filtering, and modifying of JSON data, jq is recommended due to the built-in operators and functions. Refer to the [documentation](https://stedolan.github.io/jq/manual/) for more specifc information on jq.
|
||||
|
||||
Notes:
|
||||
- `jq` must be added manually separately from the installation of changedetection.io (simply run `pip3 install jq`)
|
||||
- `jq` is not available on Windows or must be manually compiled (No "wheel" package available on pypi)
|
||||
One big advantage of `jq` is that you can use logic in your JSON filter, such as filters to only show items that have a value greater than/less than etc.
|
||||
|
||||
- The example below adds the price in dollars to each item in the JSON data, and then filters to only show items that are greater than 10.
|
||||
See the wiki https://github.com/dgtlmoon/changedetection.io/wiki/JSON-Selector-Filter-help for more information and examples
|
||||
|
||||
#### Sample input data from API
|
||||
```
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"name": "Product A",
|
||||
"priceInCents": 2500
|
||||
},
|
||||
{
|
||||
"name": "Product B",
|
||||
"priceInCents": 500
|
||||
},
|
||||
{
|
||||
"name": "Product C",
|
||||
"priceInCents": 2000
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
Note: `jq` library must be added separately (`pip3 install jq`)
|
||||
|
||||
#### Sample jq
|
||||
`jq:.items[] | . + { "priceInDollars": (.priceInCents / 100) } | select(.priceInDollars > 10)`
|
||||
|
||||
#### Sample output data
|
||||
```
|
||||
{
|
||||
"name": "Product A",
|
||||
"priceInCents": 2500,
|
||||
"priceInDollars": 25
|
||||
}
|
||||
{
|
||||
"name": "Product C",
|
||||
"priceInCents": 2000,
|
||||
"priceInDollars": 20
|
||||
}
|
||||
```
|
||||
|
||||
### Parse JSON embedded in HTML!
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ from flask_wtf import CSRFProtect
|
||||
from changedetectionio import html_tools
|
||||
from changedetectionio.api import api_v1
|
||||
|
||||
__version__ = '0.39.20.2'
|
||||
__version__ = '0.39.20.4'
|
||||
|
||||
datastore = None
|
||||
|
||||
@@ -816,8 +816,10 @@ def changedetection_app(config=None, datastore_o=None):
|
||||
|
||||
newest_file = history[dates[-1]]
|
||||
|
||||
# Read as binary and force decode as UTF-8
|
||||
# Windows may fail decode in python if we just use 'r' mode (chardet decode exception)
|
||||
try:
|
||||
with open(newest_file, 'r') as f:
|
||||
with open(newest_file, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
newest_version_file_contents = f.read()
|
||||
except Exception as e:
|
||||
newest_version_file_contents = "Unable to read {}.\n".format(newest_file)
|
||||
@@ -830,7 +832,7 @@ def changedetection_app(config=None, datastore_o=None):
|
||||
previous_file = history[dates[-2]]
|
||||
|
||||
try:
|
||||
with open(previous_file, 'r') as f:
|
||||
with open(previous_file, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
previous_version_file_contents = f.read()
|
||||
except Exception as e:
|
||||
previous_version_file_contents = "Unable to read {}.\n".format(previous_file)
|
||||
@@ -907,7 +909,7 @@ def changedetection_app(config=None, datastore_o=None):
|
||||
timestamp = list(watch.history.keys())[-1]
|
||||
filename = watch.history[timestamp]
|
||||
try:
|
||||
with open(filename, 'r') as f:
|
||||
with open(filename, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
tmp = f.readlines()
|
||||
|
||||
# Get what needs to be highlighted
|
||||
|
||||
@@ -151,28 +151,30 @@ class model(dict):
|
||||
import uuid
|
||||
import logging
|
||||
|
||||
output_path = "{}/{}".format(self.__datastore_path, self['uuid'])
|
||||
output_path = os.path.join(self.__datastore_path, self['uuid'])
|
||||
|
||||
self.ensure_data_dir_exists()
|
||||
snapshot_fname = os.path.join(output_path, str(uuid.uuid4()))
|
||||
|
||||
snapshot_fname = "{}/{}.stripped.txt".format(output_path, uuid.uuid4())
|
||||
logging.debug("Saving history text {}".format(snapshot_fname))
|
||||
|
||||
# in /diff/ and /preview/ we are going to assume for now that it's UTF-8 when reading
|
||||
# most sites are utf-8 and some are even broken utf-8
|
||||
with open(snapshot_fname, 'wb') as f:
|
||||
f.write(contents)
|
||||
f.close()
|
||||
|
||||
# Append to index
|
||||
# @todo check last char was \n
|
||||
index_fname = "{}/history.txt".format(output_path)
|
||||
index_fname = os.path.join(output_path, "history.txt")
|
||||
with open(index_fname, 'a') as f:
|
||||
f.write("{},{}\n".format(timestamp, snapshot_fname))
|
||||
f.close()
|
||||
|
||||
self.__newest_history_key = timestamp
|
||||
self.__history_n+=1
|
||||
self.__history_n += 1
|
||||
|
||||
#@todo bump static cache of the last timestamp so we dont need to examine the file to set a proper ''viewed'' status
|
||||
# @todo bump static cache of the last timestamp so we dont need to examine the file to set a proper ''viewed'' status
|
||||
return snapshot_fname
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user