rss-bot: handle feeds that don't have a title.

(imported from commit 2d95ee0cd85ac25a7c0241ce1747509e2f9c6be6)
This commit is contained in:
Jessica McKellar 2013-11-22 10:39:15 -05:00
parent 9b8555ba12
commit 1e79f5fc85

View file

@ -138,6 +138,12 @@ def compute_entry_hash(entry):
entry_id = entry.get("id", entry.get("link")) entry_id = entry.get("id", entry.get("link"))
return hashlib.md5(entry_id + entry_time).hexdigest() 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): def send_zulip(entry, feed_name):
content = "**[%s](%s)**\n%s\n%s" % (entry.title, content = "**[%s](%s)**\n%s\n%s" % (entry.title,
entry.link, entry.link,
@ -146,7 +152,7 @@ def send_zulip(entry, feed_name):
message = {"type": "stream", message = {"type": "stream",
"sender": opts.email, "sender": opts.email,
"to": opts.stream, "to": opts.stream,
"subject": feed_name, "subject": elide_subject(feed_name),
"content": content, "content": content,
} }
return client.send_message(message) return client.send_message(message)
@ -190,7 +196,9 @@ for feed_url in feed_urls:
# entries in reverse chronological order. # entries in reverse chronological order.
break 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": if response["result"] != "success":
logger.error("Error processing %s" % (feed_url,)) logger.error("Error processing %s" % (feed_url,))
logger.error(response) logger.error(response)