Ejemplo n.º 1
0
    def get(self, which):
        params = self.params(["since_id", "max_id", "count", "page", "trim_user", "include_entities"])
        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        timeline = []
        if which == "retweeted_by_me":
            timeline = td.retweeted_by_me(**params)
            title = "retweeted by me"
        elif which == "retweeted_to_me":
            timeline = td.retweeted_to_me(**params)
            title = "retweeted to me"
        elif which == "retweeted_of_me":
            timeline = td.retweets_of_me(**params)
            title = "retweeted of me"
        token_user = td.users_show_by_id(user_id=token.user_id)
        owner_user = token_user

        self.render(
            "retweets-timeline.html",
            {
                "token": token,
                "token_user": token_user,
                "owner_user": owner_user,
                "timeline": timeline,
                "max_id": str(timeline[-1]["id"] - 1) if type(timeline) == list and len(timeline) > 0 else None,
                "since_id": timeline[0]["id_str"] if type(timeline) == list and len(timeline) > 0 else None,
                "where": which,
                "which": which,
                "title": title,
            },
        )
Ejemplo n.º 2
0
    def get(self, which, slug):

        params=self.params([
            'since_id',
            'max_id',
            'count',
            'page',
            'trim_user',
            'include_entities',
        ])

        token = md.get_default_access_token()
        if not token:
            self.write(json.dumps({
                'success':False,
                'info':'No access token avaliable.',
            }))
            return 

        td = Twitdao(token)
        timeline=[]
        if which == 'retweeted_by_me':
            timeline = td.retweeted_by_me(**params)
        elif which == 'retweeted_to_me':
            timeline = td.retweeted_to_me(**params)
        elif which == 'retweeted_of_me':
            timeline = td.retweets_of_me(**params)
        token_user = td.users_show_by_id(user_id = token.user_id)
        tweets = self.render('ajax/retweets.html', {
            'token':token,
            'token_user':token_user,
            'timeline':timeline,
        }, out=False)

        if slug == 'refresh':
            next_params={}
            count=0
            if type(timeline) == list and len(timeline):
                next_params['since_id'] = str(timeline[0]['id'])
                count = len(timeline)
            else:
                tweets=''
                next_params['since_id'] = str(params['since_id'])
                count = 0

            self.write(json.dumps({
                'success':True,
                'info':'OK',
                'tweets':tweets,
                'params':next_params,
                'count':count
            }))
        else:
            next_params={}
            count=0
            if type(timeline) == list and len(timeline):
                next_params['max_id'] = str(timeline[-1]['id']-1)
                count = len(timeline)
            else:
                tweets=''
                next_params['max_id'] = str(params['max_id'])
                count = 0

            self.write(json.dumps({
                'success':True,
                'info':'OK',
                'tweets':tweets,
                'params':next_params,
                'count':count,
                'href':'/t/retweets/%s?%s' % (which, urlencode(next_params))
            }))