diff --git a/backend/__init__.py b/backend/__init__.py index 5e8adddd..9b4ca4e2 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -23,6 +23,11 @@ import queue from flask import Flask, render_template, request, send_file, send_from_directory, abort, redirect, url_for +from feedgen.feed import FeedGenerator +from flask import make_response +import datetime +import pytz + datastore = None # Local @@ -112,14 +117,41 @@ def changedetection_app(config=None, datastore_o=None): sorted_watches.sort(key=lambda x: x['last_changed'], reverse=True) existing_tags = datastore.get_all_tags() - output = render_template("watch-overview.html", - watches=sorted_watches, - messages=messages, - tags=existing_tags, - active_tag=limit_tag) + rss = request.args.get('rss') + + if rss: + fg = FeedGenerator() + fg.title('changedetection.io') + fg.description('Feed description') + fg.link(href='https://changedetection.io') + + for watch in sorted_watches: + if watch['unviewed']: + fe = fg.add_entry() + fe.title(watch['url']) + fe.link(href=watch['url']) + fe.description(watch['url']) + fe.guid(watch['uuid'], permalink=False) + dt = datetime.datetime.fromtimestamp(int(watch['newest_history_key'])) + dt = dt.replace(tzinfo=pytz.UTC) + fe.pubDate(dt) + + response = make_response(fg.rss_str()) + response.headers.set('Content-Type', 'application/rss+xml') + return response + + else: + output = render_template("watch-overview.html", + watches=sorted_watches, + messages=messages, + tags=existing_tags, + active_tag=limit_tag, + has_unviewed=datastore.data['has_unviewed']) + + # Show messages but once. + messages = [] + - # Show messages but once. - messages = [] return output @app.route("/scrub", methods=['GET', 'POST']) @@ -296,6 +328,17 @@ def changedetection_app(config=None, datastore_o=None): messages = [] return output + # Clear all statuses, so we do not see the 'unviewed' class + @app.route("/api/mark-all-viewed", methods=['GET']) + def mark_all_viewed(): + + # Save the current newest history as the most recently viewed + for watch_uuid, watch in datastore.data['watching'].items(): + datastore.set_last_viewed(watch_uuid, watch['newest_history_key']) + + messages.append({'class': 'ok', 'message': "Cleared all statuses."}) + return redirect(url_for('index')) + @app.route("/diff/", methods=['GET']) def diff_history_page(uuid): global messages diff --git a/backend/static/css/styles.css b/backend/static/css/styles.css index 8f3c0dbf..9dd75dbb 100644 --- a/backend/static/css/styles.css +++ b/backend/static/css/styles.css @@ -88,11 +88,16 @@ section.content { margin: 0 3px 0 5px; } -#check-all-button { - text-align:right; +#post-list-buttons { + text-align: right; + padding: 0px; + margin: 0px; +} +#post-list-buttons li { + display: inline-block; } -#check-all-button a { +#post-list-buttons a { border-top-left-radius: initial; border-top-right-radius: initial; border-bottom-left-radius: 5px; diff --git a/backend/store.py b/backend/store.py index 71a1867e..0d1be2e9 100644 --- a/backend/store.py +++ b/backend/store.py @@ -120,7 +120,7 @@ class ChangeDetectionStore: return 0 def set_last_viewed(self, uuid, timestamp): - self.data['watching'][uuid].update({'last_viewed': str(timestamp)}) + self.data['watching'][uuid].update({'last_viewed': int(timestamp)}) self.needs_write = True def update_watch(self, uuid, update_obj): @@ -141,6 +141,20 @@ class ChangeDetectionStore: @property def data(self): + + has_unviewed = False + + for uuid, v in self.__data['watching'].items(): + self.__data['watching'][uuid]['newest_history_key'] = self.get_newest_history_key(uuid) + if int(v['newest_history_key']) <= int(v['last_viewed']): + self.__data['watching'][uuid]['viewed'] = True + + else: + self.__data['watching'][uuid]['viewed'] = False + has_unviewed = True + + self.__data['has_unviewed'] = has_unviewed + return self.__data def get_all_tags(self): diff --git a/backend/templates/watch-overview.html b/backend/templates/watch-overview.html index ba18d323..1cb044da 100644 --- a/backend/templates/watch-overview.html +++ b/backend/templates/watch-overview.html @@ -43,8 +43,7 @@ + {% if watch.newest_history_key| int > watch.last_viewed| int %}unviewed{% endif %}"> {{ loop.index }} {{watch.title if watch.title is not none else watch.url}} @@ -76,11 +75,17 @@ -
- - Recheck +
+ + {% endblock %} \ No newline at end of file