thp / urlwatch

Watch (parts of) webpages and get notified when something changes via e-mail, on your phone or via other means. Highly configurable.
https://thp.io/2008/urlwatch/
Other
2.82k stars 352 forks source link

Shell reporter #650

Closed mhalano closed 1 year ago

mhalano commented 3 years ago

I have an edge case, but could become a feature request: I execute urlwatch locally and I would like to execute a shell command when there is any changes. The goal is to use notify-send command to display a notification in my desktop telling me about a change was detected (not necessarily what was the change). I tried to create a job to execute the command, but the message appears every time the urlwatch executes, and not only when there is a change.

mhalano commented 3 years ago

I tried to do a very hackish thing to get a notification on the desktop, but it doesn't work as expected. I put in my crontab:

[ -n "$(/usr/bin/urlwatch |/usr/bin/tee -a /home/mhalano/urlwatch.log)" ] && (eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)"; /usr/bin/notify-send "urlwatch detected a change" && echo "alert triggered" >> /home/mhalano/urlwatch.log)

The idea was executing the urlwatch, log the exit (for debug purposes only), and if there is anything on the exit, show the notification. I thought it was nice, until I get notifications even without reports (so that's why the logs, to try debugging that). The problem is the error logs: it shows in the exit but don't produce report (and I don't want to). So my idea to fix that would be a way to execute a command every time a report would be generated. What you think about it? There is another solution for that?

thp commented 2 years ago

Recent versions have diff_tool and diff_filter settings.

The diff_tool will get the old content and the new content as two filename arguments, and you can do whatever. Alternatively, if you're fine with the diff, you can use the diff_filter to do something.

An example is documented here: https://urlwatch.readthedocs.io/en/latest/advanced.html#pass-diff-output-to-a-custom-script

devicenull commented 2 years ago

I'd love to see this as well - my use case is to kick off a script to request archive.org save a page whenever it changes. I don't see a clear way of doing this, short of monitoring stdout

mborsetti commented 2 years ago

@devicenull You may want to try the fork (optimized for web monitoring) webchanges as it has such reporter: https://webchanges.readthedocs.io/en/stable/reporters.html#run-command

thp commented 2 years ago

@mborsetti Please fix the licensing issue of your fork: https://github.com/mborsetti/webchanges/issues/30

thp commented 1 year ago

Removed comment from @notdavid because that's already mentioned elsewhere, and webchanges removed copyright/license headers in its source files (it's an unfriendly fork of urlwatch), so I'd prefer not promoting it here unnecessarily.