This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/rss.py

34 lines
893 B
Python
Raw Normal View History

2012-10-17 00:24:25 +02:00
from util import hook, web, text
@hook.command("feed")
@hook.command
def rss(inp, say=None):
2012-10-17 00:24:25 +02:00
limit = 3
# 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"
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})
for row in result.rows:
2012-10-17 00:24:25 +02:00
title = text.truncate_str(row["title"], 100)
link = web.isgd(row["link"])
2012-10-17 00:24:25 +02:00
say(u"{} - {}".format(title, link))
@hook.command
def rb(inp, say=None):
2012-10-17 00:24:25 +02:00
"rb -- Shows the latest Craftbukkit recommended build"
rss("bukkit", say)