ejabberd - Comments for "patch for bash.org.ru" https://www.ejabberd.im/node/3027 en Thanks, patch committed to https://www.ejabberd.im/node/3027#comment-53331 <p>Thanks, patch committed to Neutron trunk SVN.</p> Sun, 22 Jun 2008 22:32:55 +0000 mfoss comment 53331 at https://www.ejabberd.im New patch version https://www.ejabberd.im/node/3027#comment-52399 <p>New patch version, with some fixes:</p> <pre>Index: bashorg_plugin.py =================================================================== --- bashorg_plugin.py (revision 143) +++ bashorg_plugin.py (working copy) @@ -24,20 +24,24 @@ def handler_bashorgru_get(type, source, parameters): if parameters.strip()=='': - req = urllib2.Request('http://bash.org.ru/quote.php') + req = urllib2.Request('http://bash.org.ru/random') else: - req = urllib2.Request('http://bash.org.ru/quote.php?num='+parameters.strip()) + req = urllib2.Request('http://bash.org.ru/search?text='+urllib.quote_plus(parameters.strip().encode('windows-1251'))) req.add_header = ('User-agent', 'Mozilla/5.0') + req.add_header = ('Accept-Charset', 'windows-1251') try: r = urllib2.urlopen(req) target = r.read() - od = re.search('&lt;td class="dat"&gt;',target) - message = target[od.end():] - message = message[:re.search('&lt;/td&gt;',message).start()] + od = re.search(r'&lt;div class="q"&gt;.*?&lt;div class="vote"&gt;.*?&lt;a.*?&lt;/div&gt;.*?&lt;div&gt;(.*?)&lt;/div&gt;.*?&lt;/div&gt;', target, re.DOTALL) + if od == None or od.group(1) == None: + smsg(type,source,unicode('Башорг не радует цитатами... ','koi8-u')) + return + message = od.group(1) message = decode(message) message = '\n' + message.strip() smsg(type,source,unicode(message,'windows-1251')) - except: + except Exception, e: + print str(e) smsg(type,source,unicode('Кончился интернет, всё, приехали... ','koi8-u')) def handler_linuxorgru_get(type, source, parameters): </pre> Thu, 15 May 2008 15:43:19 +0000 Anonymous comment 52399 at https://www.ejabberd.im