You Are Here:

Community: Wiki

This page was last modified on 5 November 2009, at 10:15.

How to use logs

From Forum Nokia Wiki

Reviewer Approved   



ID ... Creation date 22 march 2008
Platform S60 2nd edition, 3rd Edition Tested on devices N70, N95 8gb
Category Python Subcategory Call Logs


Keywords (APIs, classes, methods, functions): logs, time

Overview

This article describes how to read the phone's logs using Pys60. The below are some code snippets which will explain how to get information about missed calls, SMS details, Duration of calls.

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

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia