示例#1
0
 def putcmd(self, cmd):
     if self._connected:
         cmd = GO.utf8(cmd)
         self._mutex.acquire()
         if self._irc_debug: print '[-c2s-] %s'%cmd
         self._sock.sendall(cmd)
         self._sock.sendall('\r\n')
         self._mutex.release()
示例#2
0
 def wiki(self, cmd):
     (ok, kw) = self._check_for_string('%20'.join(cmd.arguments()))
     if ok:
         downloaded = urllib2.urlopen('http://ru.wikipedia.org/w/api.php?format=xml&action=opensearch&search=%s'%GO.utf8(kw))
         dom = parseString(downloaded.read())
         downloaded.close()
         root = dom.getElementsByTagName('SearchSuggestion')[0].getElementsByTagName('Section')[0]
         cnt = root.getElementsByTagName('Item').length
         if   cnt == 0:
             cmd.reply(u'Нет такого в википедии')
         elif cnt  > 1:
             for a in root.getElementsByTagName('Item'):
                 if a.getElementsByTagName('Text')[0].firstChild.data.strip() == u' '.join(cmd.arguments()):
                     cmd.reply(u'%s (%s)'%(a.getElementsByTagName('Description')[0].firstChild.data.strip(), a.getElementsByTagName('Url')[0].firstChild.data.strip()))
             cmd.reply(u'Варианты: %s'%u', '.join([a.getElementsByTagName('Text')[0].firstChild.data.strip() for a in root.getElementsByTagName('Item')]))
         elif cnt == 1:
             i = root.getElementsByTagName('Item')[0]
             cmd.reply(u'%s (%s)'%(i.getElementsByTagName('Description')[0].firstChild.data.strip(), i.getElementsByTagName('Url')[0].firstChild.data.strip()))
     else:
         cmd.reply_error(kw)