from __future__ import division import logs import appuifw import e32 import time fn=u"E:\\system\\Apps\\Python\\logs\\logs.txt" logfile = open(fn,"a") e=['out', 'missed', 'in'] for x in e: l=logs.calls(mode=x) for i in range(len(l)): dim=time.localtime(l[i]["time"]) dateim= time.strftime("%Y/%m/%d-%H:%M:%S", dim) s=str(dateim)+(" M:")+str(l[i]["direction"]) s=s+(" D:")+str(l[i]["duration"]) s=s+(" N:")+str(l[i]["number"]) nln=" ;" s=s+nln logfile.write( str(s)+'\n') logfile.close() # medzindia.blogspot.com appuifw.note(u"log Written. MIT....Email:imran-doc@hotmail.com,",'info')
Output:- 2009/mo/da-hh:mm:ss M:Outgoing N:1234567890 ; 2009/mo/da-hh:mm:ss M:Missed call N:1234567890 ; 2009/mo/da-hh:mm:ss M:Incoming N:1234567890 ; ---------------------------------------------------- comments:- from __future__ import division import logs import appuifw import e32 import time # declare a filesystem object # u for UNICODE format of file # r for windows format of file # for binary fn=u"E:\\system\\Apps\\Python\\logs\\logs.txt" # open file of the FSO # r to read # w to write # a to append logfile = open(fn,"a") # declare a tuple containing three parameters / mode-variables e=['out', 'missed', 'in'] # loop through for each mode as outgoing, missed and incoming calls # x changes to out, missed and in cyclically as declared in e # for x in e: is executed thrice for x in e: # declare log of calls with each mode cyclically starting with outgoing l=logs.calls(mode=x) #for each of the three modes loop till the mode(e.g. outgoing) list ends for i in range(len(l)): # for each entry in log, convert the time in seconds since 1970(UTC) to localtime dim=time.localtime(l[i]["time"]) # convert the dim tuple to standard format with strftime dateim= time.strftime("%Y/%m/%d-%H:%M:%S", dim) # store the formatted localtime to a string s, add alphabet M and add direction # of call as outgoing/missed/incoming # otherwise we can use the value of x as declared in for x in e: s=str(dateim)+(" M:")+str(l[i]["direction"]) # the duration of the call s=s+(" D:")+str(l[i]["duration"]) # the number called (second party) preceeded by Alph N: s=s+(" N:")+str(l[i]["number"]) # a semicolon so that you can parse the final file to a database nln=" ;" # finalize the value of string s s=s+nln # write string s to the file along with a newline logfile.write( str(s)+'\n') # for the first run the loop 'for x in e:' ends and begins with next value of x # 'for x in e:' ends with three runs # close the file logfile.close() # medzindia.blogspot.com # flash a 'info' note on the screen, UNICODE 'u' appuifw.note(u"log Written. MIT....Email:imran-doc@hotmail.com,",'info')
No comments:
Post a Comment