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.3k stars 965 forks source link

[feature] API - Marking watch as 'seen' via API #1998

Closed xconverge closed 10 months ago

xconverge commented 10 months ago

I use https://github.com/gethomepage/homepage (https://github.com/gethomepage/homepage/blob/main/src/widgets/changedetectionio/widget.js) and noticed that my diffs show as "unread" or "not seen" until they get rechecked, even if I have "viewed" them in the UI.

The code that homepage is using to show a diff is

    if (data[key].last_changed > 0 && data[key].last_checked === data[key].last_changed) {
      diffsDetected += 1;
    }

Is there something else we can expose to the API to potentially use in this widget like "unread" or "new" or something similar to what the frontend uses to bold/unbold the links in the list?

Edit: Sorry this should be a feature request not a bug, it changed as I wrote it

dgtlmoon commented 10 months ago

hey! yeah, you should set last_viewed on some action

https://github.com/dgtlmoon/changedetection.io/blob/8fd57280b741642aa6246e5102c08d4ea9050edc/changedetectionio/model/Watch.py#L116

So it means that according to the API docs at https://changedetection.io/docs/api_v1/index.html#api-Watch-Update_a_watch you can just call

Just update '{"last_viewed": 1700673833}'

so it means for example


curl http://localhost:4000/api/v1/watch/cc0cfffa-f449-477b-83ea-0caafd1dc091 -X PUT -H"x-api-key:813031b16330fe25e3780cf0325daa45" -H "Content-Type: application/json" -d '{"last_viewed": 1700673833}'

And that will work, can you do that?

dgtlmoon commented 10 months ago

or is the above answer something "homepage" can integrate?

dgtlmoon commented 10 months ago

Checking diff in frontend does not mark the diff as "seen" in the API

This is kind of misleading issue topic, because theres no way the API can really know the last time your eyes actually saw the diff..

xconverge commented 10 months ago

Ah yes perfect, I see now that I need to dive into each specific watch to check the last_viewed, that is exactly what I was looking

This can be closed now, I am not sure it would be unanimously accepted but I will maybe try it for the homepage widget and decide if I want to open a PR, thanks!

dgtlmoon commented 10 months ago

Ah yes perfect, I see now that I need to dive into each specific watch to check the last_viewed, that is exactly what I was looking

This can be closed now, I am not sure it would be unanimously accepted but I will maybe try it for the homepage widget and decide if I want to open a PR, thanks!

That would be amazing :) link this issue against your PR there so they see a +1 from me

xconverge commented 10 months ago

Can we maybe put the last_viewed field at the top level of the watch endpoint so that I don't need to make separate api calls for each watch I want to check? Looking at the homepage code, it is totally doable to do more fetches but seems a bit messy to me

Up to you, but without it, I probably wont make the change to the homepage project, since I can just run rechecks or wait for rechecks to clear the counter now that I understand the behavior

xconverge commented 10 months ago

Oops forgot to quote or tag you so you would get a notification/see this in a closed issue

@dgtlmoon

dgtlmoon commented 10 months ago

Can we maybe put the last_viewed field at the top level of the watch endpoint so that I don't need to make separate api calls for each watch I want to check? Looking at the homepage code, it is totally doable to do more fetches but seems a bit messy to me

I dont follow/understand sorry

dgtlmoon commented 10 months ago

aaah you are saying when you get the watch information, it does not include "viewed" right? ( https://changedetection.io/docs/api_v1/index.html#api-Watch-Watch )

is that what you mean by "top level" ?

dgtlmoon commented 10 months ago

Ahh there is a bug

curl -s https://hosted/api/v1/watch/ad43465c-9ecc-4b2f-a4fe-683d487a42c1  -H"x-api-key:xxxx" |jq ".viewed"

false

then I click '[diff]`

then retry the API

curl -s https://hosted/api/v1/watch/ad43465c-9ecc-4b2f-a4fe-683d487a42c1  -H"x-api-key:xxxx" |jq ".viewed"

false

xconverge commented 10 months ago

aaah you are saying when you get the watch information, it does not include "viewed" right? ( https://changedetection.io/docs/api_v1/index.html#api-Watch-Watch )

is that what you mean by "top level" ?

Yea, and I could also compute viewed if last_viewed was provided (since I have last_changed already).

Basically I would like to be able to derive/get this state/information from a single call to curl -s https://hosted/api/v1/watch without needing to loop over each watch with changes and make a separate api call

dgtlmoon commented 10 months ago

yeah there's a few missing from the API reply, I see it now

watch['viewed'] should be boolean if its been viewed since diff or not watch['link'] the actual rendered link in the case that you are using Jinja2 in your URL format watch['label'] will prefer the 'title' over the link if it is set (same as in the overview list) watch['newest_history_key'] integer - as it says

i'll check out a fix ASAP, basically just needs something set here to get it from the @property

https://github.com/dgtlmoon/changedetection.io/blob/8fd57280b741642aa6246e5102c08d4ea9050edc/changedetectionio/api/api_v1.py#L78

I'll keep this tagged as bug because that viewed status is totally wrong and could affect someone