def add_feed(self, message, keywords): try: args = message.bot_args.split(' ', 1) url = Format.remove(args[1]) # Check URL if not self._validate_url(url): raise RssException, self.lang.get('invalid_url') name = Format.remove(args[0]) regexp = re.compile('^[a-zA-Z0-9\-_.]+$') if not regexp.match(name): raise RssException, self.lang.get('invalid_name') cursor = self.connection.cursor() cursor.execute('INSERT INTO feeds (name, url) VALUES (?, ?)', (name, url)) self.connection.commit() cursor.close() self.bot.client.send_notice(message.nick, self.lang.get('feed_added')) except RssException, error: self.bot.client.send_pm(message.channel, error)
def read_feed(self, message, keywords): try: url = Format.remove(message.bot_args) # Check URL if not self._validate_url(url): url = self.get_url(url) if url == None: raise RssException, self.lang.get('not_found') rss = RssFeed(url) rss.parse(5) self.bot.client.send_pm(message.channel, Format.color('darkblue') + Format.bold() + rss.title) for item in rss: send = "[ %s%s%s ] - %s" % (Format.color('red'), item['link'], Format.normal(), item['title']) self.bot.client.send_pm(message.channel, send) except RssException, error: self.bot.client.send_pm(message.channel, error)