People who we have not communicated with in a long time
        will not appear in the look-ahead cache that Facebook keeps.
        We must manually resolve them.

        :param facebook_id: Profile ID of the user to lookup.
        :return:
338232
def _manual_lookup(self, facebook_id, facebook_id_string):
        
        resp = self._session.get(
            'https://www.facebook.com/%s' % facebook_id,
            allow_redirects=True, timeout=10
        )
        # No point in trying to get this using BeautifulSoup. The HTML here
        # is the very epitome of what it is to be invalid...
        m = _MANUAL_NAME_MATCHER.search(resp.text)
        if m:
            name = m.group(1)
        else:
            name = facebook_id_string
        self._cached_profiles[facebook_id] = name
        return name
531029
def user(id)
      if id
        cached_user = users.detect {|u| u[:id] == id }
        user = cached_user || fetch_user(id)
        self.users << user
        user
      end
    end
765054
def individual(self, ind_id=None):
        
        for ind_obj in self.individuals:
            if ind_obj.ind_id == ind_id:
                return ind_obj
        return None
507942
def looking_for(self):
        
        looking_for = self.source_profile.looking_for
        return self.dest_user.profile.looking_for.update(
            gentation=looking_for.gentation,
            single=looking_for.single,
            near_me=looking_for.near_me,
            kinds=looking_for.kinds,
            ages=looking_for.ages
        )
464155
def get_friends(self, query):
        
        # Connecting to the API
        api = self._connectToAPI()

        # Verifying the limits of the API
        self._rate_limit_status(api=api, mode="get_friends")

        # Making the call to the API
        try:
            friends_ids = api.friends_ids(query)
        except:
            return []

        """res = []
        # Extracting the information from each profile
        for a in aux:
            us= self.getUser(a)
            res.append(self._processUser(us))"""

        return friends_ids
883289
def friends(self):
        
        if self._friends is None:
            self.assert_bind_client()
            if self.friend_count > 0:
                self._friends = self.bind_client.get_athlete_friends(self.id)
            else:
                # Shortcut if we know there aren't any
                self._friends = []
        return self._friends
658674
def scoped_timeline(self, *id, **kwargs):
        
        self._validate_loaded()

        params = {'user_id': id}
        params.update(kwargs)

        resource = self.SCOPED_TIMELINE.format(id=self.id)
        response = Request(self.client, 'get', resource, params=params).perform()

        return response.body['data']
1375058
def get_id(self):
        
        if self._id is None:
            self._id = graceful_get(self.inspect(refresh=True), "ID")
        return self._id
101282
def get_cached(self, link, default=None):
        ''''''
        if hasattr(link, 'uri'):
            return self.id_map.get(link.uri, default)
        else:
            return self.id_map.get(link, default)
604830
def delete(self, id):
        ''''''
        model = self.model.objects.only('id').get_or_404(id=id)
        follow = Follow.objects.get_or_404(follower=current_user.id,
                                           following=model,
                                           until=None)
        follow.until = datetime.now()
        follow.save()
        count = Follow.objects.followers(model).count()
        return {'followers': count}, 200
1165868
def push_account_last_seen_task(obj_id):
    
    lock_id = "%s-push-account-last-seen-%s" % (settings.ENV_PREFIX, obj_id)  # noqa: E731
    acquire_lock = lambda: cache.add(lock_id, "true", LOCK_EXPIRE)  # noqa: E731
    # lock is not released on purpose. We want 5 mins cache for subsequent calls.
    # release_lock = lambda: cache.delete(lock_id)

    if acquire_lock():
        intercom_user = False
        UserModel = get_user_model()
        try:
            instance = UserModel.objects.get(pk=obj_id)
            data = {
                "user_id": instance.intercom_id,
                "email": instance.email,
                "name": instance.get_full_name(),
                "last_request_at": instance.last_login.strftime("%s") if instance.last_login else "",
            }
            if not getattr(settings, "SKIP_INTERCOM", False):
                intercom_user = intercom.users.create(**data)

            if intercom_user:
                UserModel.objects.filter(pk=obj_id).update(
                    intercom_last_api_response=intercom_user.__dict__,
                    intercom_api_response_timestamp=make_aware(datetime.now(), pytz.UTC)
                )
        except UserModel.DoesNotExist:
            raise
1263055
def get_cached(self):
        
        def id_in_list(list, id):
            if id:
                if [i for i in list if i.id == id]:
                    return True
                else:
                    raise PyPumpException("id %r not in feed." % self._since)

        tmp = []
        if self._before is not None:
            # return list based on before param
            if not id_in_list(self.feed._items, self._before):
                return tmp
            if isinstance(self._before, six.string_types):
                found = False
                for i in self.feed._items:
                    if not found:
                        if i.id == self._before:
                            found = True
                        continue
                    else:
                        tmp.append(i)
                self._before = False
            return tmp

        if self._since is not None:
            # return list based on since param
            if not id_in_list(self.feed._items, self._since):
                return tmp
            if isinstance(self._since, six.string_types):
                found = False
                for i in self.feed._items:
                    if i.id == self._since:
                        found = True
                        break
                    else:
                        tmp.append(i)
                self._since = False
            return reversed(tmp)

        if not hasattr(self, 'usedcache'):
            self.usedcache = True  # invalidate cache

            if isinstance(self._offset, int):
                # return list based on offset
                return self.feed._items[self._offset:]

            return self.feed._items
        else:
            return tmp
1159412
def cognito_idp_user_pool_arn(self, lookup, default=None):
    
    client = EFAwsResolver.__CLIENTS["cognito-idp"]
    user_pool_id = self.cognito_idp_user_pool_id(lookup, default)
    if user_pool_id == default:
      return default

    response = client.describe_user_pool(UserPoolId=user_pool_id)

    if not response.has_key("UserPool"):
      return default

    return response["UserPool"]["Arn"]
65413
def contacted(self):
        
        try:
            contacted_span = self._contacted_xpb.one_(self.profile_tree)
        except:
            return False
        else:
            timestamp = contacted_span.replace('Last contacted ', '')
            return helpers.parse_date_updated(timestamp)
986654
def get_profile_pic_from_id(self, id):
        
        profile_pic = self.wapi_functions.getProfilePicFromId(id)
        if profile_pic:
            return b64decode(profile_pic)
        else:
            return False
838122
def lookup(self):
        
        assert not self.is_existing
        try:
            a = SocialAccount.objects.get(provider=self.account.provider,
                                          uid=self.account.uid)
            # Update account
            a.extra_data = self.account.extra_data
            self.account = a
            self.user = self.account.user
            a.save()
            # Update token
            if app_settings.STORE_TOKENS and self.token:
                assert not self.token.pk
                try:
                    t = SocialToken.objects.get(account=self.account,
                                                app=self.token.app)
                    t.token = self.token.token
                    if self.token.token_secret:
                        # only update the refresh token if we got one
                        # many oauth2 providers do not resend the refresh token
                        t.token_secret = self.token.token_secret
                    t.expires_at = self.token.expires_at
                    t.save()
                    self.token = t
                except SocialToken.DoesNotExist:
                    self.token.account = a
                    self.token.save()
        except SocialAccount.DoesNotExist:
            pass
110422
def associate_by_user_id(backend, details, response, user=None, *args, **kwargs):
    
    if user:
        return None

    user_id = response.get('id')
    if user_id:
        # Try to associate accounts registered with the same Google user_id.
        for provider in ('google-appengine-oauth', 'google-appengine-oauth2'):
            social = backend.strategy.storage.user.get_social_auth(provider, user_id)
            if social:
                user = social.user
                if user:
                    return {'user': user}