--- xtalk.py 2006-10-06 20:30:42.000000000 +0800 +++ en2zh.py 2008-09-07 08:37:22.000000000 +0800 @@ -1,4 +1,6 @@ #!/usr/bin/python +# en2zh.py = xtalk.py + en2zh@bot.talk.google.com +# @Copyleft 2008 hutuworm (http://hutuworm.blogspot.com) # $Id: xtalk.py,v 1.2 2006/10/06 12:30:42 normanr Exp $ import sys,os,xmpp,time,select @@ -15,7 +17,8 @@ type = event.getType() fromjid = event.getFrom().getStripped() if type in ['message', 'chat', None] and fromjid == self.remotejid: - sys.stdout.write(event.getBody() + '\n') + sys.stdout.write(event.getBody().encode('utf8') + '\n' ) + sys.exit(0) def stdio_message(self, message): m = xmpp.protocol.Message(to=self.remotejid,body=message,typ='chat') @@ -27,22 +30,23 @@ if not con: sys.stderr.write('could not connect!\n') return False - sys.stderr.write('connected with %s\n'%con) + #sys.stderr.write('connected with %s\n'%con) auth=self.jabber.auth(jid.getNode(),jidparams['password'],resource=jid.getResource()) if not auth: sys.stderr.write('could not authenticate!\n') return False - sys.stderr.write('authenticated using %s\n'%auth) + #sys.stderr.write('authenticated using %s\n'%auth) self.register_handlers() return con if __name__ == '__main__': if len(sys.argv) < 2: - print "Syntax: xtalk JID" + print "Syntax: en2zh text" sys.exit(0) - tojid=sys.argv[1] + tojid='en2zh@bot.talk.google.com' + text=sys.argv[1] jidparams={} if os.access(os.environ['HOME']+'/.xtalk',os.R_OK): @@ -66,6 +70,8 @@ sys.exit(1) #cl.SendInitPresence(requestRoster=0) # you may need to uncomment this for old server + + bot.stdio_message(text) socketlist = {cl.Connection._sock:'xmpp',sys.stdin:'stdio'} online = 1 |
$ cat .xtalk #Uncommentfields before use and type in correct credentials.#JID=romeo@montague.net/resource (/resource is optional)#PASSWORD=juliet JID=your-id@gmail.com PASSWORD=your-password $ chmod 0600 .xtalk |
$ python en2zh.py "Bosnia and Herzegovina" 波斯尼亚和黑塞哥维那 |
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |