""" gps_service_gtalk.py Send message to gtalk user """ import xmpp import gps_auth_gtalk d = {'login':'','password':'','to':''} rslt = '' def send(msg): global d, rslt if not d['login']: default_head() cl = xmpp.Client('gmail.com',debug=[]) con = cl.connect(server=('talk.google.com',5223)) if not con: rslt = 'Connection failed.' return False auth = cl.auth(d['login'],d['password']) if not auth: rslt = 'Authentication failed.!' return False try: msg_id = cl.send(xmpp.protocol.Message(d['to'],msg)) (r, rslt) = (True, 'sent message id %s' % msg_id) except: rslt = 'Failed sending message.' r = False return r def default_head(): global d d['login'] = gps_auth_gtalk.e_user d['password'] = gps_auth_gtalk.e_pass d['to'] = gps_auth_gtalk.e_to if __name__ == "__main__": print '%s, %s' % (send('Test msg 101'), rslt)