import os.path
import evolution
-from facebook import Facebook
+from facebook import Facebook, FacebookError
import twitter
import gnome.gconf
from contacts import ContactStore
self.friends = {}
self.blocked_pictures = []
+ self.callback.progress(0, 0)
# -- Get a user session and retrieve Facebook friends...
#
pass
self.do_fb_login()
- self.callback.progress(0, 0)
# 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
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):
store = ContactStore(addresses)
print "+++ Contact store created..."
self.updated = []
+ self.unmatched = []
+ self.matched = []
contacts = addresses.get_all_contacts()
+ contacts.sort(key=lambda obj: obj.get_name())
current = 0
maximum = len(contacts)
for contact in contacts:
current += 1
self.callback.progress(current, maximum)
+ found = False
for name in names.variants(contact.get_name()):
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
- break
+ if updated:
+ self.updated.append(contact)
+ addresses.commit_contact(contact)
+ print "Saved changes to [%s]" % (contact.get_name())
+
+ break
+
+ if found:
+ self.matched.append(contact)
+ else:
+ self.unmatched.append(contact)
store.close()