Beispiel #1
0
    def _get_media(self, api, mid):
        media = spawn(api.media, mid)
        likes = spawn(api.media_likes, media_id=mid)
        gevent.joinall([media, likes])
        media, likes = media.get(), likes.get()
        errors = get_errors(media, likes)
        if errors:
            if any([e.error_type == 'APINotAllowedError' for e in errors]):
                return render('profile-noauth.html', ukey=request.ukey)
            app.logger.error([str(e) for e in errors])
            return notfound(u'服务器暂时出问题了')

        ukey = media.user.id
        isfollow = False
        if request.ukey:
            try:
                isfollow = is_follow(ukey, api)
            except InstagramAPIError:
                return notfound(u'服务器暂时出问题了')

        isstar = False
        for i in likes:
            if request.ukey and request.ukey == i.id:
                isstar = True

        isme = False
        if request.ukey and ukey == request.ukey:
            isme = True
        return dict(media=media, isme=isme, isfollow=isfollow,
                    likes=likes[:5], isstar=isstar)
Beispiel #2
0
    def _get_users(self, ukey, user_type='followed'):
        next_url = request.args.get('next_url', None)
        if next_url and 'instagram' not in next_url:
            next_url = signer.loads(next_url)
        api = InstagramAPI(access_token=request.access_token)
        user = spawn(api.user, ukey)
        if user_type == 'following':
            users = spawn(api.user_follows, ukey, with_next_url=next_url)
        else:
            users = spawn(api.user_followed_by, ukey, with_next_url=next_url)
        isfollows = False
        if request.ukey:
            isfollows = spawn(isfollow, ukey, api)
        else:
            isfollows = spawn(lambda x: False, ukey)

        gevent.joinall([user, users, isfollows])
        user, users, isfollows = user.get(), users.get(), isfollows.get()
        errors = get_errors(user, users, isfollows)
        if errors:
            app.logger.error([str(e) for e in errors])
            return notfound(u'服务器暂时出问题了')

        next_url = users[1]
        next_url = signer.dumps(next_url) if next_url else next_url
        users = users[0]

        isme = False
        if request.ukey and ukey == request.ukey:
            isme = True
        context = {
            'user': user,
            'users': users,
            'next_url': next_url,
            'isfollows': isfollows,
            'isme': isme,
        }
        return context