Reply
Thread Tools
Posts: 3 | Thanked: 0 times | Joined on Oct 2010
#1
Today I decided to figure out why Hermes doesn't work for me. It's gets most of the info, but it doesn't seem to be able to get the birthdays.

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 -
Code:
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 -

Code:
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 )
Unfortunately, this doesn't work. Does anyone have any idea on how I can set the birthday using Python? In the above script - ebook.e_contact_set( hash(con), 107, ctypes.addressof( bd )) would be where I'm trying to set the birthdate.

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.
 
Posts: 3 | Thanked: 0 times | Joined on Oct 2010
#2
Bump. Anyone?
 
yoyoek1's Avatar
Posts: 44 | Thanked: 62 times | Joined on Aug 2010 @ Polska
#3
I myself curious
my experiments shows that, it will add new.
good for beginning
Code:
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)
 
Reply


 
Forum Jump


All times are GMT. The time now is 20:37.