Страница 1 из 1

запуск скриптов python'a

Добавлено: 2010-12-02 16:10:41
QweЯty
помогите запустить jabber bota

установил cd /usr/ports/net-im/py-jabberbot

с сайта скачал код:
Example code

Код: Выделить всё

from jabberbot import JabberBot, botcmd
import datetime

class SystemInfoJabberBot(JabberBot):
    @botcmd
    def serverinfo( self, mess, args):
        """Displays information about the server"""
        version = open('/proc/version').read().strip()
        loadavg = open('/proc/loadavg').read().strip()

        return '%s\n\n%s' % ( version, loadavg, )
    
    @botcmd
    def time( self, mess, args):
        """Displays current server time"""
        return str(datetime.datetime.now())

    @botcmd
    def rot13( self, mess, args):
        """Returns passed arguments rot13'ed"""
        return args.encode('rot13')

    @botcmd
    def whoami( self, mess, args):
        """Tells you your username"""
        return mess.getFrom()
 
username = 'jid@jabber.tsure.ru'
password = 'password****'
bot = SystemInfoJabberBot(username,password)
bot.serve_forever()
попытка запуска выдает:

Код: Выделить всё

radist04ka# python jabber.bot
  File "jabber.bot", line 31
    bot.serve_forever()                                                                                                             bot.serve_forever()
                                                                                                                                      ^
SyntaxError: invalid syntax
как его запустить?

Re: запуск скриптов python'a

Добавлено: 2010-12-02 16:24:06
QweЯty
нашел вот тут еще:

Код: Выделить всё

from jabberbot import JabberBot
import datetime
 
class SystemInfoJabberBot(JabberBot):
   def bot_serverinfo( self, mess, args):
       """Displays information about the server"""
       version = open('/proc/version').read().strip()
       loadavg = open('/proc/loadavg').read().strip()
       
       return '%s\n\n%s' % ( version, loadavg, )
   
   def bot_time( self, mess, args):
       """Displays current server time"""
       return str(datetime.datetime.now())
   
   def bot_rot13( self, mess, args):
       """Returns passed arguments rot13'ed"""
       return args.encode('rot13')
   
   def bot_whoami( self, mess, args):
       """Tells you your username"""
       return mess.getFrom()
 
username = 'my-jabberid@jabberserver.example.org'
password = 'my-password'
bot = SystemInfoJabberBot(username,password)
bot.serve_forever()
ругается так теперь:

Код: Выделить всё

radist04ka# python jabber1.bot
SystemInfoJabberBot : Warning: unable to establish secure connection - TLS failed!
Traceback (most recent call last):
  File "jabber1.bot", line 27, in <module>
    bot.serve_forever()
  File "/usr/local/lib/python2.6/site-packages/jabberbot.py", line 411, in serve_forever
    conn = self.connect()
  File "/usr/local/lib/python2.6/site-packages/jabberbot.py", line 126, in connect
    authres = conn.auth(self.jid.getNode(), self.__password, self.res)
  File "/usr/local/lib/python2.6/site-packages/xmpp/client.py", line 225, in auth
    while self.SASL.startsasl=='in-process' and self.Process(1): pass
  File "/usr/local/lib/python2.6/site-packages/xmpp/dispatcher.py", line 303, in dispatch
    handler['func'](session,stanza)
  File "/usr/local/lib/python2.6/site-packages/xmpp/auth.py", line 204, in SASLHandler
    A1=C([H(C([resp['username'],resp['realm'],self.password])),resp['nonce'],resp['cnonce']])
NameError: global name 'H' is not defined