Add v0.0.6 of Hermes from source tarball
[hermes] / package / src / hermes.py
index 45bb05f..81faeac 100644 (file)
@@ -116,7 +116,7 @@ class Hermes:
         self.do_fb_login()
 
       # Get the list of friends...
-      attrs = ['uid', 'name', 'pic_big', 'birthday_date']
+      attrs = ['uid', 'name', 'pic_big', 'birthday_date', 'profile_url']
       for friend in self.fb.users.getInfo(self.fb.friends.get(), attrs):
         friend['pic'] = friend[attrs[2]]
         self.friends[friend['name']] = friend
@@ -130,8 +130,10 @@ class Hermes:
       api = twitter.Api(username=user, password=passwd)
       users = api.GetFriends()
       for friend in api.GetFriends():
-        self.friends[friend.name] = {'name': friend.name, 'pic': friend.profile_image_url, 'birthday_date': None}
+        self.friends[friend.name] = {'name': friend.name, 'pic': friend.profile_image_url, 'birthday_date': None, 'twitter_url': 'http://twitter.com/%s' % (friend.screen_name), 'homepage' : friend.url}
   
+    # TODO What if the user has *no* contacts?
+
   
   # -----------------------------------------------------------------------
   def sync_contacts(self, resync = False):
@@ -160,15 +162,32 @@ class Hermes:
         if name in self.friends:
           friend = self.friends[name]
           found = True
+          updated = False
       
           if friend['pic'] and (resync or contact.get_property('photo') is None):
-            print "Picture for %s is [%s]" % (name, friend['pic'])
-            store.set_photo(contact, friend['pic'])
-            self.updated.append(contact)
+            updated = store.set_photo(contact, friend['pic']) or updated
         
           if friend['birthday_date'] and (resync or contact.get_property('birth-date') is None):
-            print "Birthday for %s is [%s]" % (name, friend['birthday_date'])
+            date_str = friend['birthday_date'].split('/')
+            date_str.append('0')
+            updated = store.set_birthday(contact, int(date_str[1]),
+                                                  int(date_str[0]),
+                                                  int(date_str[2])) or updated
+
+          if 'profile_url' in friend and friend['profile_url']:
+            updated = store.add_url(contact, friend['profile_url'], unique='facebook.com') or updated
+            
+          if 'twitter_url' in friend and friend['twitter_url']:
+            updated = store.add_url(contact, friend['twitter_url'], unique='twitter.com') or updated
+            
+          if 'homepage' in friend and friend['homepage']:
+            updated = store.add_url(contact, friend['homepage']) or updated
     
+          if updated:
+            self.updated.append(contact)
+            addresses.commit_contact(contact)
+            print "Saved changes to [%s]" % (contact.get_name())
+            
           break
       
       if found: