×
Namespaces

Variants
Actions
(Redirected from How to use logs)

Archived:How to use logs in PySymbian

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

The PySymbian code snippets in this article show how to read the phone's logs. Information retrieved includes missed calls, SMS details, Duration of calls.

Article Metadata
Tested with
Devices(s): N70, N95 8gb
Compatibility
Platform(s): S60 2nd edition, 3rd Edition
Article
Keywords: logs, time
Created: bogdan.galiceanu (22 Mar 2008)
Last edited: hamishwillee (31 May 2013)

Contents

Preconditions

  • Logs Module is available in Pys60 1.4.4 and later.

Code Snippet

Example 1: Show the latest missed call's number.

import logs
 
l=logs.calls(mode='missed')[0] #The dictionary for the latest missed call
#Other tags are 'in' for received and 'out' for dialed
print l["number"] #Displays the value for the entry "number"

Example 2: Show a list of all the numbers from which SMS have been received.

import logs
 
l=logs.sms(mode='in')
for i in range(len(l)):print l[i]["number"]

Example 3: Show a list of the durations of all dialed calls along with their dates

from __future__ import division
import logs
 
l=logs.calls(mode='out')
durations=[]
times=[]
for i in range(len(l)):
durations.append(l[i]["duration"])
times.append(l[i]["time"])
 
#The times we added to the list are Unix timestamps, meaning seconds since 1970 00:00:00,
#so we have to convert them to dd/mm/yyyy hh:mm:ss
#We also have to take leap years into consideration
 
monthdays=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(len(times)):
#First, we get the number of years since 1970 and add it to 1970 to get the year when the call was made
y=int(times[i]/(86400*365))+1970
#Number of leap years:
ly=int((y-1969)/4)
#Number of days:
d=int(times[i]/86400)
d2=d-ly
dty=d2%365+1 #This is how many days have passed this year
j=0
while(dty>monthdays[j]):
if((j==1) and (y/4==int(y/4))):dty=dty-monthdays[j]-1
else:dty-=monthdays[j]
j+=1
j+=1
#j is the month and dty days of this month have passed
s2=int(times[i]-d*86400) #Seconds in the current day
#Now we convert those to hours
h=int(s2/3600)
#We now find the minutes left
m2=s2-h*3600
m=int(m2/60)
#Seconds left:
s=int(m2-m*60)
#For aesthetic purposes, we add a 0 in front of minutes and seconds where necessary
if(m<10):m="0"+str(m)
if(s<10):s="0"+str(s)
print durations[i]," ",dty,"/",j,"/",y," ",h+4,":",m,":",s


Example 4: Save the list of the log to a file with localtime(yyyy/mm/dd/-hh:mm:ss), mode, duration, number of all calls in the order outgoing, missed call and incoming.

import logs
import appuifw
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()
appuifw.note(u"log Written.",'info')
 
'''Output:-
yyyy/mo/da-hh:mm:ss M:Outgoing N:1234567890 ;
yyyy/mo/da-hh:mm:ss M:Missed call N:1234567890 ;
yyyy/mo/da-hh:mm:ss M:Incoming N:1234567890 ;'''

PROBLEMS: localtime(l[i]["time"]) time is not the same as diplayed in the mobile logs Still it is UTC! inspite of changing from gmtime(l[i]["time"]) Now, try to get the name of the caller/called from 'contacts'


Postcondition

The above mentioned three codes just give us a brief idea, a lot more can be done to utilize the logs module properly.

See Also

This page was last modified on 31 May 2013, at 04:05.
37 page views in the last 30 days.
×