[pybot-commits] CVS: pybot/pybot/modules rss.py,1.4,1.5
Brought to you by:
niemeyer
From: Gustavo N. <nie...@us...> - 2003-08-26 19:56:33
|
Update of /cvsroot/pybot/pybot/pybot/modules In directory sc8-pr-cvs1:/tmp/cvs-serv20387/pybot/modules Modified Files: rss.py Log Message: * pybot/misc.py: Introduced striphtml(). * pybot/rss.py: Allow all news to be colapsed in one line. Strip html from fields. Other minor changes and fixes. Index: rss.py =================================================================== RCS file: /cvsroot/pybot/pybot/pybot/modules/rss.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** rss.py 26 Aug 2003 16:21:34 -0000 1.4 --- rss.py 26 Aug 2003 19:56:23 -0000 1.5 *************** *** 19,22 **** --- 19,23 ---- from pybot.locals import * from pybot.util import feedparser + from pybot.misc import striphtml import thread import time *************** *** 24,33 **** HELP = """ You can ask me to show RSS news from any site and for any user/channel ! and server with "[dont] show (rss|news) [from] <url> [with link[s]] ! [with desc[ription][s]] [with prefix "<prefix>"] [each <n>(m|h)] ! [(on|for) (user|channel) <target>] [(on|at) server <server>]". Notice ! that the given interval is the maximum interval. To check what is being ! shown and for which targets, you can send me "show rss". You need the ! "rss" permission to use these commands. """ --- 25,35 ---- HELP = """ You can ask me to show RSS news from any site and for any user/channel ! and server with "[dont] show (rss|news) [from] <url> [[in] one line] ! [with link[s]] [with desc[ription][s]] [with prefix "<prefix>"] ! [each <n>(m|h)] [(on|for) (user|channel) <target>] [(on|at) server ! <server>]". Notice that the given interval is the maximum interval. ! """,""" ! To check what is being shown and for which targets, you can send me ! "show rss". You need the "rss" permission to use these commands. """ *************** *** 47,51 **** # Maxium news to send from a single feed per minute ! ONETIMELIMIT = 1 class RSS: --- 49,53 ---- # Maxium news to send from a single feed per minute ! ONETIMELIMIT = 5 class RSS: *************** *** 86,92 **** mm.hooktimer(60, self.update, ()) ! # [dont] show (rss|news|rss news) [from] <url> [with link[s]] [with desc[ription][s]] [with prefix "<prefix>"] [each <n>(m|h)] [[on|at|in|for] (user|channel) <target>] [[on|at|in|for] server <server>] self.re1 = regexp(refrag.dont(optional=1), r"show (?:rss |news |rss news )(?:from )?(?P<url>(?:https?|ftp)\S+)" r"(?P<links> with links?)?" r"(?P<descs> with desc(?:ription)?s?)?" --- 88,95 ---- mm.hooktimer(60, self.update, ()) ! # [dont] show (rss|news|rss news) [from] <url> [[in] one line] [with link[s]] [with desc[ription][s]] [with prefix "<prefix>"] [each <n>(m|h)] [[on|at|in|for] (user|channel) <target>] [[on|at|in|for] server <server>] self.re1 = regexp(refrag.dont(optional=1), r"show (?:rss |news |rss news )(?:from )?(?P<url>(?:https?|ftp)\S+)" + r"(?P<oneline> (?:in )?one line)?" r"(?P<links> with links?)?" r"(?P<descs> with desc(?:ription)?s?)?" *************** *** 138,146 **** server = servers.get(target.servername) lastid = None for item in cursor.fetchall(): ! if target.prefix: ! text = "%s %s" % (target.prefix, item.title) ! else: ! text = item.title if "l" in target.flags and item.link: text += " [%s]" % item.link --- 141,151 ---- server = servers.get(target.servername) lastid = None + if "1" in target.flags: + oneline = 1 + fulltext = "" + else: + oneline = 0 for item in cursor.fetchall(): ! text = item.title if "l" in target.flags and item.link: text += " [%s]" % item.link *************** *** 148,153 **** # item.description() is a method text += " - "+item["description"] ! server.sendmsg(target.target, None, text, notice=1) lastid = item.id if lastid: # Should always be true cursor.execute("update rsstarget set lastitemid=%s " --- 153,168 ---- # item.description() is a method text += " - "+item["description"] ! if oneline: ! if fulltext: ! fulltext = "%s; %s" % (fulltext, text) ! else: ! fulltext = text ! else: ! server.sendmsg(target.target, None, ! target.prefix, text, notice=1) lastid = item.id + if oneline: + server.sendmsg(target.target, None, + target.prefix, fulltext, notice=1) if lastid: # Should always be true cursor.execute("update rsstarget set lastitemid=%s " *************** *** 164,170 **** for item in items: if "title" in item: ! title = item["title"].strip() ! link = item.get("link", "").strip() ! desc = item.get("description", "").strip() cursor.execute("insert into rssitem values " "(NULL, %s, %s, %s, %s, %s)", --- 179,185 ---- for item in items: if "title" in item: ! title = striphtml(item["title"].strip()) ! link = striphtml(item.get("link", "").strip()) ! desc = striphtml(item.get("description", "").strip()) cursor.execute("insert into rssitem values " "(NULL, %s, %s, %s, %s, %s)", *************** *** 193,196 **** --- 208,213 ---- if m.group("descs"): flags += "d" + if m.group("oneline"): + flags += "1" cursor = db.cursor() if dont: *************** *** 260,264 **** (feed.id,)) for target in cursor.fetchall(): ! links, descs, prefix = "", "", "" if "l" in target.flags: links = "with links" --- 277,283 ---- (feed.id,)) for target in cursor.fetchall(): ! oneline, links, descs, prefix = ("",)*4 ! if "1" in target.flags: ! oneline = "in one line" if "l" in target.flags: links = "with links" *************** *** 278,282 **** msg.answer(" for", target.target, "on", target.servername, "each", interval, ! links, descs, prefix) else: msg.answer("%:", ["You can't", "You're not allowed to", --- 297,301 ---- msg.answer(" for", target.target, "on", target.servername, "each", interval, ! oneline, links, descs, prefix) else: msg.answer("%:", ["You can't", "You're not allowed to", |