diff options
Diffstat (limited to 'modules/rss.py')
| -rw-r--r-- | modules/rss.py | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/modules/rss.py b/modules/rss.py index 07916861..9ba23db4 100644 --- a/modules/rss.py +++ b/modules/rss.py @@ -7,10 +7,15 @@ import feedparser RSS_INTERVAL = 60 # 1 minute +SETTING_BIND = utils.Setting("rss-bindhost", + "Which local address to bind to for RSS requests", example="127.0.0.1") + @utils.export("botset", utils.IntSetting("rss-interval", "Interval (in seconds) between RSS polls", example="120")) @utils.export("channelset", utils.BoolSetting("rss-shorten", "Whether or not to shorten RSS urls")) +@utils.export("serverset", SETTING_BIND) +@utils.export("channelset", SETTING_BIND) class Module(ModuleManager.BaseModule): _name = "RSS" def on_load(self): @@ -27,7 +32,7 @@ class Module(ModuleManager.BaseModule): link = entry.get("link", None) if shorten: try: - link = self.exports.get_one("shorturl")(server, link) + link = self.exports.get("shorturl")(server, link) except: pass link = " - %s" % link if link else "" @@ -49,26 +54,36 @@ class Module(ModuleManager.BaseModule): if server and channel_name in server.channels: channel = server.channels.get(channel_name) for url in urls: - if not url in hooks: - hooks[url] = [] - hooks[url].append((server, channel)) + bindhost = channel.get_setting("rss-bindhost", + server.get_setting("rss-bindhost", None)) + + if url.startswith("www."): + url = url.replace("www.", "", 1) + + key = (url, bindhost) + if not key in hooks: + hooks[key] = [] + + hooks[key].append((server, channel)) if not hooks: return requests = [] - for url in hooks.keys(): - requests.append(utils.http.Request(url, id=url)) + for url, bindhost in hooks.keys(): + requests.append(utils.http.Request(url, id=f"{url} {bindhost}", + bindhost=bindhost)) pages = utils.http.request_many(requests) - for url, channels in hooks.items(): - if not url in pages: + for (url, bindhost), channels in hooks.items(): + key = f"{url} {bindhost}" + if not key in pages: # async url get failed continue try: - data = pages[url].decode() + data = pages[key].decode() except Exception as e: self.log.error("Failed to decode rss URL %s", [url], exc_info=True) |
