def send_ping(client): def pong_handler(stanza): #print'*'*20 #print stanza pass def pong_timeout_handler(*args, **kwargs): print 'PONG TIMEOUT!' print args, kwargs raise TimeoutException time_delta = int(time.time() - send_ping._last_ping_time) if time_delta < 120: return client_jid = JID(settings.JABBER_BOT_SETTINGS['jid']) ping = Iq(to_jid=client_jid.domain, from_jid=client_jid, stanza_type='get') ping.new_query('urn:xmpp:ping', name='ping') client.get_stream().set_response_handlers(ping, res_handler=pong_handler, err_handler=lambda x: x, timeout_handler=pong_timeout_handler, timeout=120) client.get_stream().send(ping) send_ping._last_ping_time = time.time()
def vcard_command(request): def vcard_success(stanza): try: vcard = VCard(stanza.get_node().get_children()) profile = request.user.get_profile() profile.update_from_vcard(vcard) except ValueError: print stanza.get_node().get_children() def vcard_error(stanza): print '*' * 50 print '!ERROR!' print stanza pass user = request.user user_jid = user.email get_vcard_req = Iq(to_jid=user_jid, from_jid=request.to_jid, stanza_type='get') get_vcard_req.new_query('vcard-temp', name='vCard') request.stream.set_response_handlers(get_vcard_req, res_handler=vcard_success, err_handler=vcard_error) request.stream.send(get_vcard_req) return "Updating..."