2012-10-17 20:30:21 +02:00
|
|
|
from util import hook, http, web, text
|
2012-10-17 00:00:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
@hook.command("feed")
|
|
|
|
@hook.command
|
2013-10-01 05:55:18 +02:00
|
|
|
def rss(inp, message=None):
|
2013-09-04 12:30:04 +02:00
|
|
|
"""rss <feed> -- Gets the first three items from the RSS feed <feed>."""
|
2012-10-17 00:24:25 +02:00
|
|
|
limit = 3
|
|
|
|
|
2012-10-17 00:00:43 +02:00
|
|
|
# preset news feeds
|
|
|
|
strip = inp.lower().strip()
|
|
|
|
if strip == "bukkit":
|
|
|
|
feed = "http://dl.bukkit.org/downloads/craftbukkit/feeds/latest-rb.rss"
|
|
|
|
limit = 1
|
|
|
|
elif strip == "xkcd":
|
|
|
|
feed = "http://xkcd.com/rss.xml"
|
2012-10-17 00:24:25 +02:00
|
|
|
elif strip == "ars":
|
|
|
|
feed = "http://feeds.arstechnica.com/arstechnica/index"
|
2012-10-17 00:00:43 +02:00
|
|
|
else:
|
|
|
|
feed = inp
|
|
|
|
|
|
|
|
query = "SELECT title, link FROM rss WHERE url=@feed LIMIT @limit"
|
2012-10-17 00:24:25 +02:00
|
|
|
result = web.query(query, {"feed": feed, "limit": limit})
|
2012-10-17 20:30:21 +02:00
|
|
|
|
|
|
|
if not result.rows:
|
|
|
|
return "Could not find/read RSS feed."
|
|
|
|
|
2012-10-17 00:00:43 +02:00
|
|
|
for row in result.rows:
|
2012-10-17 00:24:25 +02:00
|
|
|
title = text.truncate_str(row["title"], 100)
|
2012-10-17 20:30:21 +02:00
|
|
|
try:
|
|
|
|
link = web.isgd(row["link"])
|
|
|
|
except (web.ShortenError, http.HTTPError, http.URLError):
|
|
|
|
link = row["link"]
|
2013-10-01 05:55:18 +02:00
|
|
|
message(u"{} - {}".format(title, link))
|
2012-10-17 00:00:43 +02:00
|
|
|
|
|
|
|
|
2012-10-18 03:38:53 +02:00
|
|
|
@hook.command(autohelp=False)
|
2013-10-01 05:55:18 +02:00
|
|
|
def rb(inp, message=None):
|
2013-09-04 12:30:04 +02:00
|
|
|
"""rb -- Shows the latest Craftbukkit recommended build"""
|
2013-10-01 05:55:18 +02:00
|
|
|
rss("bukkit", message)
|