mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-31 21:41:33 +00:00
Moving slow-ass follow-back query to the end of the twitter/facebook import process, so at least we have the profile photo.
This commit is contained in:
parent
f2e53ed255
commit
4a0bab6bef
1 changed files with 41 additions and 37 deletions
|
@ -1682,6 +1682,8 @@ class MSocialServices(mongo.Document):
|
|||
|
||||
def sync_twitter_friends(self):
|
||||
user = User.objects.get(pk=self.user_id)
|
||||
logging.user(user, "~BB~FRTwitter import starting...")
|
||||
|
||||
api = self.twitter_api()
|
||||
if not api:
|
||||
logging.user(user, "~BB~FRTwitter import ~SBfailed~SN: no api access.")
|
||||
|
@ -1704,8 +1706,6 @@ class MSocialServices(mongo.Document):
|
|||
self.syncing_twitter = False
|
||||
self.save()
|
||||
|
||||
self.follow_twitter_friends()
|
||||
|
||||
profile = MSocialProfile.get_user(self.user_id)
|
||||
profile.location = profile.location or twitter_user.location
|
||||
profile.bio = profile.bio or twitter_user.description
|
||||
|
@ -1716,41 +1716,7 @@ class MSocialServices(mongo.Document):
|
|||
if not profile.photo_url or not profile.photo_service:
|
||||
self.set_photo('twitter')
|
||||
|
||||
def sync_facebook_friends(self):
|
||||
user = User.objects.get(pk=self.user_id)
|
||||
graph = self.facebook_api()
|
||||
if not graph:
|
||||
logging.user(user, "~BB~FRFacebook import ~SBfailed~SN: no api access.")
|
||||
self.syncing_facebook = False
|
||||
self.save()
|
||||
return
|
||||
|
||||
friends = graph.get_connections("me", "friends")
|
||||
if not friends:
|
||||
logging.user(user, "~BB~FRFacebook import ~SBfailed~SN: no friend_ids.")
|
||||
self.syncing_facebook = False
|
||||
self.save()
|
||||
return
|
||||
|
||||
facebook_friend_ids = [unicode(friend["id"]) for friend in friends["data"]]
|
||||
self.facebook_friend_ids = facebook_friend_ids
|
||||
self.facebook_refresh_date = datetime.datetime.utcnow()
|
||||
self.facebook_picture_url = "//graph.facebook.com/%s/picture" % self.facebook_uid
|
||||
self.syncing_facebook = False
|
||||
self.save()
|
||||
|
||||
self.follow_facebook_friends()
|
||||
|
||||
facebook_user = graph.request('me', args={'fields':'website,bio,location'})
|
||||
profile = MSocialProfile.get_user(self.user_id)
|
||||
profile.location = profile.location or (facebook_user.get('location') and facebook_user['location']['name'])
|
||||
profile.bio = profile.bio or facebook_user.get('bio')
|
||||
if not profile.website and facebook_user.get('website'):
|
||||
profile.website = facebook_user.get('website').split()[0]
|
||||
profile.save()
|
||||
profile.count_follows()
|
||||
if not profile.photo_url or not profile.photo_service:
|
||||
self.set_photo('facebook')
|
||||
self.follow_twitter_friends()
|
||||
|
||||
def follow_twitter_friends(self):
|
||||
social_profile = MSocialProfile.get_user(self.user_id)
|
||||
|
@ -1781,6 +1747,44 @@ class MSocialServices(mongo.Document):
|
|||
|
||||
return following
|
||||
|
||||
def sync_facebook_friends(self):
|
||||
user = User.objects.get(pk=self.user_id)
|
||||
logging.user(user, "~BB~FRFacebook import starting...")
|
||||
|
||||
graph = self.facebook_api()
|
||||
if not graph:
|
||||
logging.user(user, "~BB~FRFacebook import ~SBfailed~SN: no api access.")
|
||||
self.syncing_facebook = False
|
||||
self.save()
|
||||
return
|
||||
|
||||
friends = graph.get_connections("me", "friends")
|
||||
if not friends:
|
||||
logging.user(user, "~BB~FRFacebook import ~SBfailed~SN: no friend_ids.")
|
||||
self.syncing_facebook = False
|
||||
self.save()
|
||||
return
|
||||
|
||||
facebook_friend_ids = [unicode(friend["id"]) for friend in friends["data"]]
|
||||
self.facebook_friend_ids = facebook_friend_ids
|
||||
self.facebook_refresh_date = datetime.datetime.utcnow()
|
||||
self.facebook_picture_url = "//graph.facebook.com/%s/picture" % self.facebook_uid
|
||||
self.syncing_facebook = False
|
||||
self.save()
|
||||
|
||||
facebook_user = graph.request('me', args={'fields':'website,bio,location'})
|
||||
profile = MSocialProfile.get_user(self.user_id)
|
||||
profile.location = profile.location or (facebook_user.get('location') and facebook_user['location']['name'])
|
||||
profile.bio = profile.bio or facebook_user.get('bio')
|
||||
if not profile.website and facebook_user.get('website'):
|
||||
profile.website = facebook_user.get('website').split()[0]
|
||||
profile.save()
|
||||
profile.count_follows()
|
||||
if not profile.photo_url or not profile.photo_service:
|
||||
self.set_photo('facebook')
|
||||
|
||||
self.follow_facebook_friends()
|
||||
|
||||
def follow_facebook_friends(self):
|
||||
social_profile = MSocialProfile.get_user(self.user_id)
|
||||
following = []
|
||||
|
|
Loading…
Add table
Reference in a new issue