08年用Python写的一个塞班S60V3上免费发短信的小程序

#-*-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("\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("号码不能为空"),'error',1)
            return
        after_time=appuifw.query(cn("输入时延:"),'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)
        box.set_unread(msgid,0)
        rmsg=appuifw.Text()
        rmsg.add(cn("发件人:%s\n\n%s\n") %(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)

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
塞班60 PYTHON API The Python for S60 Platform (Python for S60) simplifies application development and provides a scripting solution for the Symbian C++ APIs. This document is for Python for S60 release 1.3.13 that is based on Python 2.2.2. The documentation for Python for S60 includes three documents: • Getting Started with Python for S60 Platform [5] contains information on how to install Python for S60 and how to write your first program. • This document contains API and other reference material. • Programming with Python for S60 Platform [6] contains code examples and programming patterns for S60 devices that can be used as a basis for programs. Python for S60 as installed on a S60 device consists of: • Python execution environment, which is visible in the application menu of the device and has been written in Python on top of Python for S60 Platform (see S60 SDK documentation [4]) • Python interpreter DLL • Standard and proprietary Python library modules • S60 UI application framework adaptation component (a DLL) that connects the scripting domain components to the S60 UI • Python Installer program for installing Python files on the device, which consists of: – Recognizer plug-in – Symbian application written in Python The Python for S60 developer discussion board [9] on the Forum Nokia Web site is a useful resource for finding out information on specific topics concerning Python for S60. You are welcome to give feedback or ask questions about Python for S60 through this discussion board. 1.1 Scope This document includes the information required by developers to create applications that use Python for S60, and some advice on extending the platform. 1.2 Audience This guide is intended for developers looking to create programs that use the native features and resources of the S60 phones. The reader should be familiar with the Python
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值