示例#1
0
文件: media.py 项目: zongxiao/Zhinsta
    def get(self, mid):
        api = InstagramAPI(access_token=request.access_token)
        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
        isfollows = False
        if request.ukey:
            try:
                isfollows = isfollow(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 render('media.html', media=media, isme=isme,
                      isfollow=isfollows, likes=likes[:5], isstar=isstar)
示例#2
0
文件: media.py 项目: Zhinsta/Zhinsta
 def post(self, mid):
     api = InstagramAPI(access_token=request.access_token)
     form = MediaCommentForm()
     if not form.validate():
         media_info = self._get_media(api, mid)
         return render('media.html', form=form, **media_info)
     api.create_media_comment(media_id=mid, text=form.content.data)
     media_info = self._get_media(api, mid)
     return render('media.html', form=form, **media_info)
示例#3
0
文件: media.py 项目: Zhinsta/Zhinsta
 def get(self, mid):
     api = InstagramAPI(access_token=request.access_token)
     result = self._get_media(api, mid)
     if not isinstance(result, dict):
         return result
     media_info = result
     form = MediaCommentForm()
     return render('media.html', form=form, **media_info)
示例#4
0
文件: user.py 项目: Zhinsta/Zhinsta
 def get(self):
     total = UserModel.query.count()
     current_page = request.args.get('page', 1)
     pager = Pager(members_per_page, total)
     pager.set_current_page(current_page)
     users = (UserModel.query
              .order_by(UserModel.date_created.desc())
              .offset(pager.offset)
              .limit(pager.limit).all())
     return render('members.html', users=users, pager=pager)
示例#5
0
文件: user.py 项目: Zhinsta/Zhinsta
    def get(self, ukey):
        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 = gevent.spawn(wrap_errors(InstagramAPIError, api.user),
                            user_id=ukey)
        feeds = gevent.spawn(wrap_errors(InstagramAPIError,
                             api.user_recent_media),
                             user_id=ukey, with_next_url=next_url)
        if request.ukey:
            isfollows = spawn(isfollow, ukey, api)
        else:
            isfollows = spawn(lambda x: False, ukey)

        gevent.joinall([user, feeds, isfollows])
        user, feeds, isfollows = user.get(), feeds.get(), isfollows.get()
        errors = [e for e in (user, feeds, isfollows)
                  if isinstance(e, InstagramAPIError)]
        if errors:
            if any([e.error_type == 'APINotAllowedError' for e in errors]):
                return render('profile-noauth.html', ukey=ukey)
            if any([e.error_type == 'APINotFoundError' for e in errors]):
                return notfound(u'用户不存在')
            app.logger.error([str(e) for e in errors])
            return apierror(u'服务器暂时出问题了')

        next_url = feeds[1] if feeds else None
        next_url = signer.dumps(next_url) if next_url else next_url
        feeds = feeds[0] if feeds else []
        isme = False
        if request.ukey and ukey == request.ukey:
            isme = True
        return render(
            'profile.html',
            user=user,
            feeds=feeds,
            isme=isme,
            isfollow=isfollows,
            next_url=next_url
        )
示例#6
0
文件: search.py 项目: Zhinsta/Zhinsta
 def get(self):
     wd = request.args.get("wd", "")
     api = InstagramAPI(access_token=request.access_token)
     tags = gevent.spawn(api.tag_search, wd)
     gevent.joinall([tags])
     try:
         tags = tags.get()
     except InstagramAPIError, e:
         if e.error_type == "APINotAllowedError":
             return render("search-tag.html", wd=wd)
         return notfound(u"服务器暂时出问题了")
示例#7
0
文件: user.py 项目: zongxiao/Zhinsta
    def get(self):
        next_url = request.args.get('next_url', None)

        api = InstagramAPI(access_token=request.access_token)
        feed = gevent.spawn(api.user_media_feed, with_next_url=next_url)

        gevent.joinall([feed])
        try:
            feed = feed.get()
        except InstagramAPIError:
            return notfound(u'服务器暂时出问题了')

        next_url = feed[1]
        media = feed[0]
        return render('feed.html', media=media, next_url=next_url)
示例#8
0
文件: show.py 项目: Zhinsta/Zhinsta
 def get(self, time_order=False):
     q = ShowModel.query.filter_by(showable=0)
     total = q.count()
     current_page = request.args.get('page', 1)
     pager = Pager(members_per_page, total)
     pager.set_current_page(current_page)
     if time_order:
         medias =\
             (q
              .order_by(ShowModel.date_tagged.desc())
              .order_by(ShowModel.date_created.desc())
              .offset(pager.offset)
              .limit(pager.limit).all())
     else:
         mids = redis.lrange('zhinsta:show:list', pager.offset, pager.offset + pager.limit - 1)
         medias = [ShowModel.query.get(x) for x in mids]
     return render('show.html', medias=medias, pager=pager)
示例#9
0
文件: media.py 项目: Zhinsta/Zhinsta
    def get(self, name):
        next_url = request.args.get('next_url', None)

        api = InstagramAPI(access_token=request.access_token)
        tag = api.tag(name)
        media = api.tag_recent_media(tag_name=name,
                                     with_next_url=next_url)
        tag = gevent.spawn(api.tag, name)
        media = gevent.spawn(api.tag_recent_media,
                             tag_name=name, with_next_url=next_url)
        gevent.joinall([tag, media])
        try:
            tag, media = tag.get(), media.get()
        except InstagramAPIError:
            return notfound(u'服务器暂时出问题了')

        next_url = media[1]
        media = media[0]
        return render('tag.html', tag=tag, media=media, next_url=next_url)
示例#10
0
文件: home.py 项目: zongxiao/Zhinsta
 def get(self):
     likes = (LikeModel.query
              .filter(LikeModel.ukey == '448621019')
              .order_by(LikeModel.date_created.desc())
              .limit(5).all())
     access_token = random.choice(OPEN_ACCESS_TOKENS)
     api = InstagramAPI(access_token=access_token)
     media = api.media(likes[0].media)
     if isinstance(media, InstagramAPIError):
         return notfound(u'服务器暂时出问题了')
     medias = ShowModel.query.filter(
         ShowModel.mid.in_([x.media for x in likes[1:]]))
     users = (RecommendModel.query
              .order_by(RecommendModel.order.desc())
              .limit(24).all())
     return render('home.html',
                   media=media,
                   medias=medias,
                   users=users)
示例#11
0
文件: user.py 项目: Zhinsta/Zhinsta
 def get(self, ukey):
     context = self._get_users(ukey, user_type='following')
     if isinstance(context, tuple):
         return context
     context['message'] = u'关注中'
     return render('follower.html', **context)
示例#12
0
文件: home.py 项目: zongxiao/Zhinsta
 def get(self):
     return render('about.html')
示例#13
0
文件: home.py 项目: zongxiao/Zhinsta
 def get(self):
     ukey = session.get('ukey', '')
     user = UserModel.query.get(ukey)
     return render('welcome.html', name=user.username, img=user.pic)