Fixed rss.py up a bit with a 'cant read feed' message and error handling for the URL shortener

This commit is contained in:
Luke Rogers 2012-10-18 07:30:21 +13:00
parent 3d747815a2
commit 3ac3111a8e

View file

@ -1,4 +1,4 @@
from util import hook, web, text from util import hook, http, web, text
@hook.command("feed") @hook.command("feed")
@ -21,9 +21,16 @@ def rss(inp, say=None):
query = "SELECT title, link FROM rss WHERE url=@feed LIMIT @limit" query = "SELECT title, link FROM rss WHERE url=@feed LIMIT @limit"
result = web.query(query, {"feed": feed, "limit": limit}) result = web.query(query, {"feed": feed, "limit": limit})
if not result.rows:
return "Could not find/read RSS feed."
for row in result.rows: for row in result.rows:
title = text.truncate_str(row["title"], 100) title = text.truncate_str(row["title"], 100)
try:
link = web.isgd(row["link"]) link = web.isgd(row["link"])
except (web.ShortenError, http.HTTPError, http.URLError):
link = row["link"]
say(u"{} - {}".format(title, link)) say(u"{} - {}".format(title, link))