Open lemon24 opened 3 years ago
Related comment:
Misc thoughts:
url
of the wrapper exception be?Just a thought.
Consider API semantics that allows for a plugin to only mark feed url for a change. Then, after processing all of the plugins, you check if any plugin requested a change (and maybe make sure only one did it?), and make the change itself as part of the processing mechanism that runs outside of the plugins.
This is subtle change, but that way you (probably) can drop requirement that such plugin must run as a last one. Also, this seem to simplify issues you mention in the last point and allows for controlling if such request makes sense in the context of any other plugins or other external factors that may occur.
EDIT: typo
@zifot, that's actually a great idea, thank you!
I think it's doable right now with tags:
def after_feed_update(reader, feed, ...):
# runs for each feed
new_url = is_permanent_redirect(feed, ...)
if new_url:
reader.set_tag(feed, '.url-change-needed', new_url)
def after_feeds_update(reader):
# runs after all the feeds
for feed in reader.get_feeds(tags=['.url-change-needed']):
new_url = reader.get_tag(feed, '.url-change-needed')
# for later: how do we deal with InvalidFeedURLError?
reader.change_feed_url(feed, new_url)
reader.delete_tag(new_url, '.url-change-needed')
Note to self: This seems like a very useful pattern, mention it in the docs for plugin authors (when we have them). The way we're handling .reader.dedupe.once for entry_dedupe is vaguely similar (mark, then change).
https://feedparser.readthedocs.io/en/latest/http-redirect.html