dgtlmoon / changedetection.io

The best and simplest free open source web page change detection, website watcher, restock monitor and notification service. Restock Monitor, change detection. Designed for simplicity - Simply monitor which websites had a text change for free. Free Open source web page change detection, Website defacement monitoring, Price change notification
https://changedetection.io
Apache License 2.0
17.09k stars 957 forks source link

[feature] found useful Jinja2 template: count of changes/adds/removes/substring #2405

Open 198thread opened 3 months ago

198thread commented 3 months ago

Version and OS

docker + slack notifications

Is your feature request related to a problem? Please describe.

Could not get numerical data from notifications

Describe the solution you'd like

I wanted a way to get the count of occurrences of a word.

Describe the use-case and give concrete real-world examples

I have no way of knowing the number of games available on sale on a website, but I can get notifications changes.

**Useful** Notifications of count (and tracking this over time). 
**Less Useful** State of web page at an interval.

Using Jinja2 templating, and some hackery, flask_app.py accepts the following when taking in an update_worker instance:

$notification_placeholder.count("$matching_word")

User testing required to see if these break, but they're working fairly well for this:

Notifications Body
    add_count == {{ diff_added.count("added") }}

Caveat re: priorities I understand difflib and diff.render pipe into update_worker and integration of counts like this may not be at the top of the kanban, but a simple solution is to add this into the _common_fields.html at line 111:

                                    <tr>
                                        <td><code>{{ '{{ diff_added.count("added") }}' }}</code></td>
                                        <td>number of items added</td>
                                    </tr>
                                    <tr>
                                        <td><code>{{ '{{ diff_removed.count("removed") }}' }}</code></td>
                                        <td>number of items added</td>
                                    </tr>
                                    <tr>
                                        <td><code>{{ '{{ current_snapshot.count("shoes") }}' }}</code></td>
                                        <td>number of times the word "shoes" appears</td>
                                    </tr>

Caveat re: integration into queue This would avoid calling diff.render a 5th time. Most crucially, it would avoid trying to update a threaded queue with new notification labels. Python's queue is threadsafe but updating a queue seems breeding ground for race-conditions

The updates to the _common_fields.html is simpler, for an advanced user feature.

Caveat re: insecurity The notification placeholders accept some python methods, likely whatever flask's environment has. This may lead to privilege escalation when run natively. Recommend running in rootless Docker/using seccomp/ufw