def _do_send(self, message_chunk, recipients_chunk): # Go to send page and check login response = self.connection.send(self.SEND_PAGE) time.sleep(2) tree = lxml.html.fromstring(response) smspage = tree.get_element_by_id("message", None) if smspage is None: if tree.get_element_by_id("top-register-btn", None): raise exceptions.LoginError("Tried to send webtext while not logged in", webtexter=self) raise exceptions.MessageSendingError("Unknown error sending webtext", webtexter=self) # Append dummy empty recipients for i in range(5-len(recipients_chunk)): recipients_chunk.append(u"") # First get Apache Token tree = BeautifulSoup(response) token = "" token = str(tree.find('input',attrs={'name':'org.apache.struts.taglib.html.TOKEN'})['value']) send_data = { "org.apache.struts.taglib.html.TOKEN":token, "message":message_chunk, "sendnow":"Send+Now", "futuredate":"false", "futuretime":"false", } # Add recipients for i,r in enumerate(recipients_chunk): send_data['recipients[%s]'%i] = str(r) # Send response = self.connection.send(self.SEND_POST, send_data) tree = lxml.html.fromstring(response) sendpage = tree.get_element_by_id('webtext-thankyou', None) if sendpage is not None and "Message sent!" in sendpage.text_content(): return True raise exceptions.MessageSendingError("Message not sent", webtexter=self)