#-*-coding:utf-8-*-import appuifw2 as Appuifwimport e32import urllibimport key_codesimport uitricksimport Contactsimport messagingimport envyimport socketimport Inboximport timedef cn (str): Return Str.decode ("Utf-8") class Mai N:def __init__ (self): Self.ap=socket.access_point (1) socket.set_default_access_point (Self.ap) sel F.names = [] self.numbers=[] SELF.NUMBER=APPUIFW. Text () Self.msg=appuifw. Text (0) self.box = Inbox. Inbox () self.box.bind (self.receivemsg) self.db = Contacts.open () for I in Self.db:self.na Mes.append (Self.db[i].title) num=self.db[i].find (' Mobile_number ') [0].value if Len (num) ==11: Self.numbers.append (num) elif num[:3]==cn ("+86"): Self.numbers.append (num[3:]) Elif NUM[:3]==CN ("the"): Self.numbers.append (num[5:]) else:self.numbers.append (num) self.names=self.names[2:] Self.numbers=self.numbers[2:] Self.number.set_case (APPUIFW. Elowercase) def hide (self): Envy.set_app_hidden (1) e32.start_exe (' Z:\\sys\\bin\\phone.exe ', "") sel F.writemessage () def send (self,snumber,smessage): For i in Snumber:if i== ': Continue try:url= ' HTTP://FETIONAPI.APPSPOT.COM/API/?FROM=15996945532&PW=459320480&A mp;to=%s&msg=%s '% (urllib.quote (i), Urllib.quote (smessage)) Answer=urllib.urlopen (URL) if Answer.read () [: 3]!= ' Yes ': appuifw.note ("Network send failed, enable SMS Mode"), "conf", 1) messaging.sms_ Send (I,CN (message), ' UCS2 ') Except:appuifw.note (CN ("network connection failed, enable SMS Mode"), "conf", 1) Mes Saging.sms_send (I,CN (smessage), ' UCS2 ') Continue def search_contact (self): INDEX=APPUI Fw.multi_selection_list (self.names,style= ' checkbox ', search_field=1) For I in Index:phonenumber=self.numbers[i] if Self.number.len () ==0:self.numb Er.add (phonenumber+ '; ') Elif self.number.get () [ -1]== '; ': Self.number.add (phonenumber+ '; ') Else:self.number.add ('; ') +phonenumber+ '; ') def addreciver (self): Appuifw.app.body=self.number appuifw.app.title=cn ("Add Contacts") Appuifw.app. Menu=[(CN ("Send Now"), Self.sendnow), (CN ("Delayed Send"), Self.senddelay), (CN ("Add Contacts"), Self.search_contact), (CN ("Exit program"), Self.app_exit)] Appuifw.app.body.bind (key_codes. Ekeyselect,self.search_contact) Appuifw.app.body.bind (key_codes. Ekeyyes,self.sendnow) Appuifw.app.exit_key_handler=self.writemessage Uitricks.set_text (CN ("Back"), 3009) def writemessage (self): appuifw.app.body=self.msg appuifw.app.title=cn ("Write short interest") appuifw.app.me Nu=[(CN ("Add Contacts"), Self.addreciver), (CN ("Exit program"), Self.app_exit)] Appuifw.apP.exit_key_handler=self.hide Self.msg.bind (key_codes. Ekeyselect,self.addreciver) Self.msg.bind (key_codes. Ekeyyes,self.addreciver) Uitricks.set_text (CN ("hidden"), 3009) def sendnow (self): If Len (self.number.get ()) ==0:appuifw.note (CN ("number cannot be empty"), ' Error ', 1) return Self.hide () Sendto=self.getsendnumber () sel F.msg.add (CN ("\ n")) Sendmsg=self.msg.get (). Encode ("Utf-8") Self.msg.clear () self.send (sendto,sendmsg) Self.ap.stop () def senddelay (self): If Len (Self.number.get ()) ==0:appuifw.note (CN ("number cannot be empty"), ' Error ', 1) return After_time=appuifw.query (CN ("Input delay:"), ' time ') self.hide () sendto=self. Getsendnumber () Self.msg.add (CN ("\ n")) Sendmsg=self.msg.get (). Encode ("Utf-8") self.msg.clear () E32.ao_sleep (After_time,lambda:self.send (sendto,sendmsg)) self.ap.stop () def getsendnumber (self): Sendnumber=self.number.geT (). Split (';') If Len (Sendnumber[0]) <11:for J in Range (0,len (self.names)-1): If self.names[j]==sendnumber[ 0]: Sendnumber[0]=self.numbers[j] self.number.clear () return Sendnumber def app_exit (self): Appuifw.app.set_exit () def receivemsg (self,msgid): Envy.set_app_hidden (0) box = Inbox. Inbox () msgcontent=box.content (MsgId) msgaddress=box.address (msgid) msgtime=box.time (MsgId) Bo X.set_unread (msgid,0) rmsg=appuifw. Text () Rmsg.add (CN ("Sender:%s\n\n%s\n")% (msgaddress,msgcontent)) Rtime=time.strftime ("Time:%m-%d-%x", Time.localt IME (Msgtime)). Decode ("Utf-8") Rmsg.add (rtime) Rmsg.read_only=1 appuifw.app.body=rmsg APPUIFW.A PP.TITLE=CN ("Inbox") Try:appuifw.app.menu=[(CN ("Reply"), lambda:self.reply (msgaddress)), (CN ("Forwarding"), lambda:self . Transform (Msgcontent))] Except:appuifw. Note (CN ("Oh")) Appuifw.query (Traceback.print_exc (), "Query") e32.start_exe (' c:\\sys\\bin\\mysms_0x111111 11.exe ', "") def reply (self,rnumber): Try:self.number.add (Rnumber) self.writemessage () Except Exception,data:print Exception, ",", Data def Transform (self,rmsg): Self.msg.add (rmsg) Self.addreciver () if __name__ = = ' __main__ ': Start=main () Envy.set_app_system (1) e32.ao_sleep (0,start.hide )
08 a small program of free texting on Saipan S60v3 written in Python