Notices


Reply
Thread Tools
m750's Avatar
Posts: 249 | Thanked: 345 times | Joined on Aug 2010 @ Italy
#1
Hello,
sorry for my poor English.
I made a script in python and sqlite3 to delete SMS from certain phone numbers.
The script works fine, but sometimes I found mismatch between rtcom-messaging-ui and the database rt-com-eventolgger.
I would then use the rtcom_el_delete_event, but I can not understand how to use it. I'm trying to use some examples, but always i get "segmentation error fault".
Could someone help me? Thanks.

Script python/sqlite3:
PHP Code:
import sqlite3 
import 
array
elimina = []

# limite = numero sms da mantenere
# limite = max number of SMS

limite 2

# elimina = numeri da cui provengono gli sms - non inserire i nomi presenti in agenda, ma i numeri/nomi reali
# elimina = phone number to delete

elimina "Ovi Store""+39...."

conn=sqlite3.connect("/home/user/.rtcom-eventlogger/el-v1.db"

cur conn.cursor()

if 
limite 0limite 0

for item in elimina:
#    print item
# trova numero di record totali
    
cur.execute("select count(remote_uid) from events where service_id = 3 and remote_uid = ?",([item]))

    
righe_t cur.fetchone()
    
righe_totali righe_t[0]

    
cancella righe_totali limite

    
while cancella 0:
        
cur.execute("select id from events where service_id = 3 and remote_uid = ?", [item])
        
id_sms cur.fetchone()
        
riga id_sms
        
#print "riga", riga
        
cur.execute("select * from events where id = ?", (riga))
        
record_da_cancellare cur.fetchall()

        
# cancellazione record
        
cur.execute("select group_uid from events where service_id = 3 and remote_uid = ?", [item])
        
gruppo cur.fetchone()
        
cur.execute("select total_events from groupcache where group_uid = ?", (gruppo))
        
totali cur.fetchone()

        
cur.execute("delete from events where id = ?", (riga))

        if 
limite == cur.execute("update groupcache set total_events = 0, read_events = 0 where group_uid = ?"gruppo)
        
#if limite == 0 : cur.execute("delete from groupcache where group_uid = ?", gruppo)

        
cancella cancella 1

conn
.commit();
cur.close(); 
Script (not working) in python/sqlite3/rtcom api
PHP Code:
import sqlite3 
import 
array
import ctypes

elimina 
= []

# limite = numero sms da mantenere
# limite = max number of SMS

limite 2

# elimina = numeri da cui provengono gli sms - non inserire i nomi presenti in agenda, ma i numeri/nomi reali
# elimina = phone number to delete

elimina "Ovi Store""+39...."

# added for deleting messaging via rtcom
class RTComElEvent(ctypes.Structure):
    
_fields_ = [("_mask"ctypes.c_int),
                (
"event_id"ctypes.c_int)]

def del_sms(id_):
    
rtcom ctypes.CDLL('librtcom-eventlogger.so.1.1.0'# PR 1.3 ?
    #rtcom = ctypes.CDLL('librtcom-eventlogger.so.1')     # PR 1.2
    #rtcom = ctypes.CDLL('librtcom-eventlogger.so.0')     # PR 1.1

    
el ctypes.cast(rtcom.rtcom_el_delete_event (), ctypes.c_void_p)
    
event ctypes.cast(rtcom.rtcom_el_delete_event (), ctypes.POINTER(RTComElEvent))[0]

    
event._mask       |= << 6
    event
.fld_  id_

    rtcom
.rtcom_el_event_free(ctypes.byref(event))
    
rtcom.rtcom_el_event_free_content(ctypes.byref(event)) # aggiunta io


conn=sqlite3.connect("/home/user/.rtcom-eventlogger/el-v1.db"

cur conn.cursor()

if 
limite 0limite 0

for item in elimina:
    print 
item
# trova numero di record totali
    
cur.execute("select count(remote_uid) from events where service_id = 3 and remote_uid = ?",([item]))

    
righe_t cur.fetchone()
    
righe_totali righe_t[0]

    
cancella righe_totali limite

    
while cancella 0:
        
cur.execute("select id from events where service_id = 3 and remote_uid = ?", [item])
        
id_sms cur.fetchone()
        print 
"id_sms "id_sms[0]
        
riga id_sms
        
print "riga"riga
        cur
.execute("select * from events where id = ?", (riga))
        
record_da_cancellare cur.fetchall()

        
# cancellazione record
        
cur.execute("select group_uid from events where service_id = 3 and remote_uid = ?", [item])
        
gruppo cur.fetchone()
        
cur.execute("select total_events from groupcache where group_uid = ?", (gruppo))
        
totali cur.fetchone()
        
cancella cancella 1

# added for deleting messaging via rtcom        
        
del_sms(id_sms)


conn.commit();
cur.close(); 

Last edited by m750; 2010-11-04 at 18:08.
 
Posts: 187 | Thanked: 41 times | Joined on May 2010
#2
try this

Code:
def del_sms(id):
OSSO_CTX      =   osso.Context("some_context_here", "0.1")
OSSO_EL       =   ctypes.CDLL('librtcom-eventlogger.so.1')
OSSO_OBJ      =   OSSO_EL.rtcom_el_new()
OSSO_EL.rtcom_el_delete_event(OSSO_OBJ,int(id),None)
i'd like to know how to insert an event in the database via python ...
 
m750's Avatar
Posts: 249 | Thanked: 345 times | Joined on Aug 2010 @ Italy
#3
Doesn't work

The script does not give me an error, but the event is not deleted and i must stop the execution with "Ctrl+Z"

Please, have you any idea how to resolve?


Originally Posted by colchaodemola View Post
i'd like to know how to insert an event in the database via python ...
Via sqlite3 or via rtcom?
try to look at this script
http://www.frals.se/maemo/rtcom.py
 
Posts: 187 | Thanked: 41 times | Joined on May 2010
#4
Originally Posted by m750 View Post
Doesn't work

The script does not give me an error, but the event is not deleted and i must stop the execution with "Ctrl+Z"

Please, have you any idea how to resolve?
You need to run as user user and using run-standalone.sh python your_program.py



Via sqlite3 or via rtcom?


try to look at this script
http://www.frals.se/maemo/rtcom.py
via rtcom , i saq the rtcom.py and try to change it to add a call event but unsuccessfull :/
 
Posts: 187 | Thanked: 41 times | Joined on May 2010
#5
ok , i can add a call event , now i need to delete an event by group_uid and i dont know what i am doing wrong...

i know there is the method :
Code:
gboolean rtcom_el_delete_by_group_uids  	(  	RTComEl *   	 el,
		const gchar **  	group_uids	 
	)
so i want to do in python
rtcom_el_delete_by_group_uids(el,'the group id as string') but it seg faults

how do i send the type gchar** in python using ctypes ?
 
m750's Avatar
Posts: 249 | Thanked: 345 times | Joined on Aug 2010 @ Italy
#6
where am I wrong?



Originally Posted by colchaodemola View Post
how do i send the type gchar** in python using ctypes ?
have you tried to use cStringIO ?
 

The Following User Says Thank You to m750 For This Useful Post:
Posts: 187 | Thanked: 41 times | Joined on May 2010
#7
i really dont know what the problem is...
i use that same piece of code in a very complex program listening dbus events and handling the call backs ... maybe it only works in a dbus loop ... no idea though...
i was able to send the gchar ** using pointer(pointer(char)) from ctypes...
now i am finally able to force send the damn refreshhint signal...
 
Posts: 9 | Thanked: 0 times | Joined on Dec 2010
#8
Originally Posted by colchaodemola View Post
i really dont know what the problem is...
i use that same piece of code in a very complex program listening dbus events and handling the call backs ... maybe it only works in a dbus loop ... no idea though...
i was able to send the gchar ** using pointer(pointer(char)) from ctypes...
now i am finally able to force send the damn refreshhint signal...
colchaodemola, could you check the thread about the sms counter where you modified the script to count the outgoing sms? I wanted to add a counter for the incomoing sms, but i can't figure it out how to do it.
 
Reply


 
Forum Jump


All times are GMT. The time now is 21:56.