def get_source(self):
return self._source
+ def set_source(self, source):
+ self._source = source
+
def get_nickname(self):
return self._safe_get("nickname")
self._add(key, value)
def update_contact(self, contact, overwrite=False):
- """
- Updates the contact with information from this object,
- without overwriting unless overwrite is set to True.
- """
+ """Updates the contact with information from this object,
+ without overwriting unless overwrite is set to True.
+ Returns flag indicating if anything *was* changed."""
- # FIXME: currently we overwrite everything
- self._if_defined('photo-url', contact.set_photo)
- self._if_defined('nickname', contact.set_nickname)
+ def set_birthday(arg):
+ # Hackily assumes Facebook format
+ date_str = arg.split('/')
+ date_str.append('0')
+ return contact.set_birthday(int(date_str[1]),
+ int(date_str[0]),
+ int(date_str[2]))
+
+ updated = False
+ if overwrite or contact.get_photo() is None: updated += self._if_defined('photo-url', contact.set_photo)
+ if overwrite or contact.get_nickname() is None: updated += self._if_defined('nickname', contact.set_nickname)
+ if overwrite or contact.get_birthday() is None: updated += self._if_defined('bday', set_birthday)
if self._multi_attributes.has_key('url'):
for url in self._multi_attributes['url']:
- contact.add_url(url)
+ updated += contact.add_url(url)
+
+ return updated
- def fixme(arg):
- pass
- #print "FIXME - birthday date needs to be parsed/fixed %s before calling contact.set_birthday" % arg
- self._if_defined('bday', fixme)
# private helpers -----------------------
#
return False
def _if_defined(self, key, callback):
- if self._attributes.has_key(key):
- callback(self._attributes[key])
+ return self._attributes.has_key(key) and callback(self._attributes[key]) or False
def _has(self, key):
return self._attributes.has_key(key) or self._multi_attributes.has_key(key)