08年にPythonで書いたサイパンS 60 V 3で無料でメールを送る小さなプログラム


#-*-coding:utf-8-*-
import appuifw2 as appuifw
import e32
import urllib
import key_codes
import uitricks
import contacts
import messaging
import envy
import socket
import inbox
import time
def cn(str):
    return str.decode("utf-8")

class main:

    def __init__(self):
        self.ap=socket.access_point(1)
        socket.set_default_access_point(self.ap)
        self.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.names.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("125"):
                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',"")
        self.writemessage()            
    def send(self,snumber,smessage):
    
        for i in snumber:
            if i=='':
                continue
            try:
                url='http://fetionapi.appspot.com/api/?from=15996945532&pw=459320480&to=%s&msg=%s' %(urllib.quote(i),urllib.quote(smessage))
                answer=urllib.urlopen(url)
                if answer.read()[:3]!='Yes':
                    appuifw.note(cn("      ,      "),"conf",1)
                    messaging.sms_send(i,cn(message),'UCS2')
            except:
                appuifw.note(cn("      ,      "),"conf",1)
                messaging.sms_send(i,cn(smessage),'UCS2')
                continue
		
    
    def search_contact(self):
        
        index=appuifw.multi_selection_list(self.names,style='checkbox',search_field=1)
        for i in index:
            phonenumber=self.numbers[i]
            if   self.number.len()==0:
                self.number.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("     ")
        appuifw.app.menu=[(cn("    "),self.sendnow),(cn("    "),self.senddelay),(cn("     "),self.search_contact),(cn("    "),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("  "),3009)
       
		
    def writemessage(self):
     
        appuifw.app.body=self.msg
        appuifw.app.title=cn("   ")
        appuifw.app.menu=[(cn("     "),self.addreciver),(cn("    "),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("  "),3009)
      
    def sendnow(self):
        if len(self.number.get())==0:
	    appuifw.note(cn("      "),'error',1)
	    return
        self.hide()
        sendto=self.getsendnumber()
        self.msg.add(cn("
")) 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(" "),'error',1) return after_time=appuifw.query(cn(" :"),'time') self.hide() sendto=self.getsendnumber() self.msg.add(cn("
")) 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) box.set_unread(msgid,0) rmsg=appuifw.Text() rmsg.add(cn(" :%s

%s
") %(msgaddress,msgcontent)) rtime=time.strftime(" :%m-%d-%X",time.localtime(msgtime)).decode("utf-8") rmsg.add(rtime) rmsg.read_only=1 appuifw.app.body=rmsg appuifw.app.title=cn(" ") try: appuifw.app.menu=[(cn(" "),lambda:self.reply(msgaddress)),(cn(" "),lambda:self.transform(msgcontent))] except : appuifw.note(cn("oh")) appuifw.query(traceback.print_exc(),"query") e32.start_exe('C:\\sys\\bin\\mysms_0x11111111.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)