Skip to content
This repository has been archived by the owner on Feb 11, 2019. It is now read-only.

Commit

Permalink
Merge branch 'feature/issue-12-debug-logs' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
annasborysova committed Jul 7, 2015
2 parents 7c7fe12 + bee581b commit 5e001b9
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions vxyowsup/whatsapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ def setup_transport(self):
stack_client = self.stack_client = StackClient(CREDENTIALS, self)
self.client_d = deferToThread(stack_client.client_start)
self.client_d.addErrback(self.catch_exit)
self.client_d.addErrback(self.print_error)
self.client_d.addErrback(self.log_error)

@defer.inlineCallbacks
def teardown_transport(self):
print "Stopping client ..."
log.info("Stopping client ...")
self.stack_client.client_stop()
yield self.client_d
yield self.redis._close()
print "Loop done."
log.info("Loop done.")

def handle_outbound_message(self, message):
# message is a vumi.message.TransportUserMessage
log.info('Sending %r' % (message.to_json(),))
log.debug('Sending %r' % (message.to_json(),))
msg = TextMessageProtocolEntity(message['content'], to=message['to_addr'] + '@s.whatsapp.net')
self.redis.setex(msg.getId(), self.config.ack_timeout, message['message_id'])
self.stack_client.send_to_stack(msg)
Expand All @@ -87,10 +87,10 @@ def _send_delivery_report(self, whatsapp_id):

def catch_exit(self, f):
f.trap(WhatsAppClientDone)
print "Yowsup client killed."
log.info("Yowsup client killed.")

def print_error(self, f):
print f
def log_error(self, f):
log.error(f)
return f


Expand All @@ -116,10 +116,10 @@ def client_start(self):
self.stack.loop(discrete=0, count=1, timeout=1)

def client_stop(self):
print "Stopping client ..."
log.info("Stopping client ...")

def _stop():
print "Sending disconnect ..."
log.info("Sending disconnect ...")
self.whatsapp_interface.disconnect()

def _kill():
Expand Down Expand Up @@ -154,8 +154,8 @@ def onMessage(self, messageProtocolEntity):
messageProtocolEntity.getParticipant())
self.toLower(receipt)

print "You have received a message, and thusly sent a receipt"
print "You are now sending a reply"
log.debug('You have received a message, and thusly sent a receipt')
# log.debug("You are now sending a reply")
# self.send_to_human('iiii', from_address + '@s.whatsapp.net', "this transport's gone rogue")

reactor.callFromThread(self.transport.publish_message,
Expand All @@ -167,9 +167,9 @@ def onMessage(self, messageProtocolEntity):
def onReceipt(self, entity):
'''receives confirmation of delivery to human'''
# shady?
print "The user you attempted to contact has received the message"
print "You are sending an acknowledgement of their accomplishment"
print entity.getType()
log.debug("The user you attempted to contact has received the message")
log.debug("You are sending an acknowledgement of their accomplishment")
log.debug(entity.getType())
ack = OutgoingAckProtocolEntity(entity.getId(), "receipt", entity.getType(), entity.getFrom())
self.toLower(ack)
# if receipt means that it got delivered to the whatsapp user then
Expand All @@ -185,6 +185,6 @@ def onAck(self, ack):
'''receives confirmation of delivery to server'''
# sent_message_id: whatsapp id
# user_message_id: vumi_id
print "WhatsApp acknowledges your " + ack.getClass()
log.debug('WhatsApp acknowledges your %s.' % ack.getClass())
if ack.getClass() == "message":
reactor.callFromThread(self.transport._send_ack, ack.getId())

0 comments on commit 5e001b9

Please sign in to comment.