mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-17 06:00:42 +01:00
RSS: Add support for ETag and Last-Modified.
This commit is contained in:
parent
db50e65b86
commit
f3b31e5a4b
@ -63,6 +63,7 @@ announced_headlines_filename = \
|
|||||||
|
|
||||||
class Feed:
|
class Feed:
|
||||||
__slots__ = ('url', 'name', 'data', 'last_update', 'entries',
|
__slots__ = ('url', 'name', 'data', 'last_update', 'entries',
|
||||||
|
'etag', 'modified',
|
||||||
'lock', 'announced_entries')
|
'lock', 'announced_entries')
|
||||||
def __init__(self, name, url, plugin_is_loading=False, announced=None):
|
def __init__(self, name, url, plugin_is_loading=False, announced=None):
|
||||||
assert name, name
|
assert name, name
|
||||||
@ -76,6 +77,8 @@ class Feed:
|
|||||||
# loaded (the bot could be starting, and thus already busy)
|
# loaded (the bot could be starting, and thus already busy)
|
||||||
self.last_update = time.time() if plugin_is_loading else 0
|
self.last_update = time.time() if plugin_is_loading else 0
|
||||||
self.entries = []
|
self.entries = []
|
||||||
|
self.etag = None
|
||||||
|
self.modified = None
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
self.announced_entries = announced or \
|
self.announced_entries = announced or \
|
||||||
utils.structures.TruncatableSet()
|
utils.structures.TruncatableSet()
|
||||||
@ -240,10 +243,16 @@ class RSS(callbacks.Plugin):
|
|||||||
|
|
||||||
def update_feed(self, feed):
|
def update_feed(self, feed):
|
||||||
with feed.lock:
|
with feed.lock:
|
||||||
d = feedparser.parse(feed.url)
|
d = feedparser.parse(feed.url, etag=feed.etag,
|
||||||
feed.data = d.feed
|
modified=feed.modified)
|
||||||
feed.entries = d.entries
|
if 'status' not in d or d.status != 304: # Not modified
|
||||||
feed.last_update = time.time()
|
if 'etag' in d:
|
||||||
|
feed.etag = d.etag
|
||||||
|
if 'modified' in d:
|
||||||
|
feed.modified = d.modified
|
||||||
|
feed.data = d.feed
|
||||||
|
feed.entries = d.entries
|
||||||
|
feed.last_update = time.time()
|
||||||
self.announce_feed(feed)
|
self.announce_feed(feed)
|
||||||
|
|
||||||
def update_feed_in_thread(self, feed):
|
def update_feed_in_thread(self, feed):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user