You <-> Eliza Google chat program
Today , I have completed one of my dream programs : I never thought that using only this much lines, I will be able to complete that .. Thanks to Python and Unni.
Well, my dream goes like this
” What if I can connect the google chat program with the Eliza program.” : Which in non technical dream terms, What if I have a program which helps the Artificial intelligent program called Eliza to give replies to my friends, instead of me. Those who are chatting with me will think that at the other end, there is a human being (in this case, me) who is replying to their chats.
That is my presence is there in google chat but actually I am not there.. A software “Maya”
The eliza_googlechat.py
##################################################################################
# You <-> Eliza Google chat program #
# What: #
# #
# This program will login as you in the google chat and will automagically reply #
# to those who are ‘thinking’ that they are chatting with you using the eliza #
# AI program. #
# How: #
# #
# The google chat handling/reply part is done using the xmpppy python module #
# Chats from your friends will be passed to the eliza program and the resulting #
# output will be returned back to your friends as though you have typed it. #
# Who: #
# #
# Maxin B. John <maxinbjohn@gmail.com> This code is small and self explanatory #
# So I haven’t added a single comment in this program. #
##################################################################################
import xmpp
import time
from eliza import *
def messageCB(sess,mess):
nick=mess.getFrom().getResource()
text=mess.getBody()
reply = eliza(text)
sess.send(xmpp.Message(mess.getFrom(),reply))
def LoopyFn(conn):
try:
conn.Process(1)
except KeyboardInterrupt:
return 0
return 1
def main_process():
jid = xmpp.protocol.JID(‘maxinbjohn@gmail.com’)
cl = xmpp.Client(‘gmail.com’)
cl.connect((‘talk.google.com’,5223))
cl.RegisterHandler(‘message’,messageCB)
cl.auth(jid.getNode(),’my_secret_password’)
cl.sendInitPresence()
while LoopyFn(cl):
pass
if __name__ == ‘__main__’:
main_process()
The eliza.py program to integrate the eliza program with the above program
####################################################################
# This program will talk with eliza, the psychiatrist AI program #
# By Maxin B. John <maxinbjohn@gmail.com> #
####################################################################
import httplib
import urllib
#Function that POSTS the string to eliza website and formats the reply
# my_dialog is the string that we POST to the www-ai.ijs.si website
# obtains the reply from eliza scripts and prints it on the screen
def eliza(my_dialog):
params = urllib.urlencode({‘Entry1′: my_dialog})
headers = {“Content-type”: “application/x-www-form-urlencoded”,”Accept”: “text/plain”}
conn = httplib.HTTPConnection(“www-ai.ijs.si”)
conn.request(“POST”, “/eliza-cgi-bin/eliza_script”, params, headers)
response = conn.getresponse()
data = response.read()
reply_from_eliza= str(data.split(‘</strong>’)[2]).split(‘\n’)[1]
return “%s\r\n” % (reply_from_eliza,)
conn.close()
# invoking the eliza function to test it’s functionality in pythonic way
if __name__== ‘__main__’:
str =eliza(‘I love python’)
print str
Well, from now onwards, I can dream of other possibilities . So let me sleep now 