From 1e79f5fc85f5ae9058c2c9d50c6a8cdefea18b37 Mon Sep 17 00:00:00 2001 From: Jessica McKellar Date: Fri, 22 Nov 2013 10:39:15 -0500 Subject: [PATCH] rss-bot: handle feeds that don't have a title. (imported from commit 2d95ee0cd85ac25a7c0241ce1747509e2f9c6be6) --- integrations/rss/rss-bot | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/integrations/rss/rss-bot b/integrations/rss/rss-bot index fcaceb8..ad2dd70 100755 --- a/integrations/rss/rss-bot +++ b/integrations/rss/rss-bot @@ -138,6 +138,12 @@ def compute_entry_hash(entry): entry_id = entry.get("id", entry.get("link")) return hashlib.md5(entry_id + entry_time).hexdigest() +def elide_subject(subject): + MAX_TOPIC_LENGTH = 60 + if len(subject) > MAX_TOPIC_LENGTH: + subject = subject[:MAX_TOPIC_LENGTH - 3].rstrip() + '...' + return subject + def send_zulip(entry, feed_name): content = "**[%s](%s)**\n%s\n%s" % (entry.title, entry.link, @@ -146,7 +152,7 @@ def send_zulip(entry, feed_name): message = {"type": "stream", "sender": opts.email, "to": opts.stream, - "subject": feed_name, + "subject": elide_subject(feed_name), "content": content, } return client.send_message(message) @@ -190,7 +196,9 @@ for feed_url in feed_urls: # entries in reverse chronological order. break - response = send_zulip(entry, data.feed.title) + feed_name = data.feed.title or feed_url + + response = send_zulip(entry, feed_name) if response["result"] != "success": logger.error("Error processing %s" % (feed_url,)) logger.error(response)