def post(self): #check if logged in admin_pwd=self.request.cookies.get("admin_pwd") if admin_pwd==VALID_PWD: #send dummy text voice=Voice() voice.login("*****@*****.**", "robots25") voice.send_sms(7865533061, "I am a machine") self.response.out.write("message sent") else: self.redirect('/login')
class Sms: def __init__(self, username, password): print "Initializing..." self.voice = Voice() print "Logging in..." try: self.voice.login(username, password) except: print "Error logging in" # print "Going to retry from the beginning" # Sms(username, password) print "Updating SMS..." self.id = None self.number = None self.fails = 0 self.voice.sms() self.msgs = util.extractsms(self.voice.sms.html) threading.Timer(10, self.update).start() while True: self.prompt() def update(self): try: self.voice.sms() oldmsgs = self.msgs self.msgs = util.extractsms(self.voice.sms.html) if len(self.msgs) != len(oldmsgs): sys.stdout.write('\a') sys.stdout.flush() self.fails = 0 except: #Fail silently, but keep a running tab of the number of failures. self.fails += 1 if self.fails > 5: print "Error Updating" t = threading.Timer(10, self.update) t.daemon = True t.start() def prompt(self): for i in range(50): print "" if self.id == None: self.setId() for msg in self.msgs: if msg['id'] == self.id: if msg['from'] == 'Me:': print ">>>" + msg['text'] else: print msg['text'] try: usr_in = str(raw_input(">>>")) if usr_in == "--conversation" or usr_in == "-c": self.setId() elif usr_in == "--number" or usr_in =="-n": self.setNumber() elif usr_in[:2] == "--": print "I don't think that is what you meant..." else: self.voice.send_sms(self.number, usr_in) except SyntaxError: print "Error on Send" def setId(self): ids = [] for msg in self.msgs: if msg['id'] not in ids: ids.append(msg['id']) if self.id != None: print "Current conversation: ", ids.index(self.id) d = json.loads(self.voice.sms.json)['messages'] for i in range(len(ids)): print i, " ", d[ids[i]]['displayNumber'] inp = raw_input("id: ") if inp == "" and self.id == None: print "You must enter an id" self.setId() if inp != "": try: self.id = ids[int(inp)] self.number = d[self.id]['displayNumber'] except: print "Invalid id" self.setId() def setNumber(self): print "Current number: ", self.number inp = raw_input("Number: ") if inp != "": try: self.number = str(inp) except: print "Invalid number" self.setNumber()
def send(): voice=Voice() voice.login("*****@*****.**", "robots25") voice.send_sms(5512062642, "I am a machine")