|
From: Waseem S. D. <wd...@MI...> - 2005-06-03 15:57:10
|
Interesting approach.
I probably don't understand where you're going with this though, because
I wonder why you'd want to save state internally at all? Whatever lives
in Gmail should be the definitive version of the contacts, right? So why
would we ever need to read from them locally?
Though I guess it can't hurt.
- W
On Fri, 2005-06-03 at 17:32 +0200, Stas Z wrote:
> I was hacking gmailagent to add a 'save contacts when something goes
> wrong' function.
> It occurs to me that libgmail2 does very little to save the contacts
> in case or errors.
>
> I just paste the stuff I come up with for gmailagent.
> (It can be found in Gmail.py)
>
> Stas
>
> def save_contacts(contacts):
> """Save the contact in case of an error. This is an attempt to prevent
> data loss in case of an error when interacting with Gmail contacts."""
> try:
> f = open(os.path.expanduser('~/.GmailContacts.pickle'),'w')
> pickle.dump(contacts,f)
> ## XXX TODO: some way to load the pickled object and restore it
> except Exception,info:
> text = "Attempt to pickle the contacts %s" % str(info)
> logging.critical(text)
> f.close()
> try:
> f =open(os.path.expanduser('~/.GmailContacts.txt'),'w')
> text = "#An error occured in GmailAgent and these contacts are
> saved\n"+\
> "#to this file in an attempt to save them\n"+\
> "#A contact is saved as follows:\n"+\
> "#GmailID Name email notes\n"
> f.write(text)
> for con in contacts:
> name,email,notes,id =
> con.getName(),con.getEmail(),con.getNotes(),con.getId()
> f.write("%s %s %s %s\n" % (con.getId(),\
> con.getName(),\
> con.getEmail(),\
> con.getNotes()))
> f.close()
> except Exception,info:
> logging.critical(str(info))
> return str(info)
>
>
|