|
|
2010-10-19
, 06:40
|
|
|
Posts: 44 |
Thanked: 62 times |
Joined on Aug 2010
@ Polska
|
#3
|

import evolution
addresses = evolution.ebook.open_addressbook('default')
c = evolution.ebook.EContact("""BEGIN:VCARD
VERSION:3.0
FN:FirstName LastName
N:LastName;FirstName;;;
EMAIL;TYPE=INTERNET:aaa.bbb@abc.pl
TEL;TYPE=CELL:123-123-345
ADR:;;;;;;
END:VCARD
BEGIN:VCARD""")
addresses.add_contact(c)
After going through 'Hermes' source code ( I'm more of a C++ programmer ). I gave up. It was clear that I needed the SDK if I wanted to debug it. Just reading the source code wasn't going to cut it.
Eventually I decided to forget about Hermes and write a simple Python script to do it myself -
The Hard part ( or so I thought ) -
Getting the data from facebook -
import json import urllib def get_fb_data( id ) : key = "?access_token=2227470867|2.xBA6NCznBb7fIFwaQjilEQ__.3600.1286114400-542059084|rK0dnLILxIqioQ8vhwzDOrTbQOc" base = "https://graph.facebook.com/" url = base + str(id) + key sock = urllib.urlopen( url ) js = json.load( sock ) return js def get_birthdays() : friends = get_fb_data("me/friends")['data'] birthdays = [] for f in friends : id = f['id'] #print "Getting data for ( ", f['name'], ", ", f['id']," )" fdata = get_fb_data( int(id) ) if 'birthday' in fdata : t = (fdata['name'], fdata['birthday']) birthdays.append( t ) print t return birthdays print get_birthdays()Saving the Data -
Firstly, the maemo python documentation is horrible - This is no documentation!! Understanding how contacts are stored is a nightmare. I had to go through the relevant parts of hermes and pick up the code from there -
import evolution import ctypes abook = evolution.ebook.open_addressbook("default") contacts = abook.get_all_contacts() ebook = ctypes.CDLL('libebook-1.2.so.5') def get_contact( nick ) : for con in contacts : nickname = con.get_property('nickname') if not nickname : continue if nick in nickname : return con class EContactDate(ctypes.Structure): _fields_ = [('year', ctypes.c_uint), ('month', ctypes.c_uint), ('day', ctypes.c_uint)] def set_birthdate( con, day, month, year= 0 ) : if year == 0 : year = 2010 bd = EContactDate() bd.year = year bd.month = month bd.day = day ebook.e_contact_set( hash(con), 107, ctypes.addressof( bd )) ut = get_contact('Utkarsh') set_birthdate( ut, 22, 12, 1990 )If none knows, I might try to do it in C ( ugh! ) next weekend.
PS : If anyone wants to try out the facebook script, they'll need their own access_token. The simplest way is to go to http://developers.facebook.com/docs/api click on any one of the given queries, and copy the access token from the url.