Пример #1
0
    def post(self, id):
        params = self.params(['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)
        message = td.direct_messages_destroy(id=id, **params)

        if 'error' in message:
            self.write(json.dumps({
                'success':False,
                'info':message['error'],
            }))
        else:
            self.write(json.dumps({
                'success':True,
                'info':'OK',
                'message':message,
            }))
Пример #2
0
    def get(self, screen_name, slug, xlug):
        
        params = self.params(['since_id','max_id','per_page','page','include_entities'])

        token = md.get_default_access_token()
        if not token:
            self.redirect('/settings')
            return

        td = Twitdao(token)
        token_user = td.users_show_by_id(user_id = token.user_id)
        owner_user = td.users_show_by_screen_name(screen_name = screen_name)
        #ls = td.user_list_id_get(id=slug, screen_name=screen_name)
        timeline = td.user_list_id_statuses(id=slug, screen_name = screen_name, **params)

        tweets=self.render('ajax/list.html', {
            'token':token,
            'token_user':token_user,
            'owner_user':owner_user,
            #'list':ls,
            'timeline':timeline,
        },out=False)

        if xlug == '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/%s/%s?%s'% (screen_name, slug, urlencode(next_params))
            }))
Пример #3
0
    def post(self):
        screen_name = self.param('screen_name')
        user_id = self.param('user_id')
        text = self.param('text')

        params = self.params(['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)
        message = td.direct_messages_new(user_id=user_id, screen_name=screen_name, text=text.encode('utf-8'), **params)

        if 'error' in message:
            self.write(json.dumps({
                'success':False,
                'info':message['error'],
            }))
        else:
            self.write(json.dumps({
                'success':True,
                'info':'OK',
                'message':message,
            }))
Пример #4
0
    def post(self, screen_name):
        token = md.get_default_access_token()
        if not token:
            self.write(json.dumps({
                'success':False,
                'info':'No access token avaliable.',
            }))
            return

        td = Twitdao(token)
        ruser = td.report_spam(screen_name = screen_name)
        taskqueue.add(queue_name='cache', url='/q/update_user_cache', params={'tk':token.key(), 'user_id':token.user_id}, method="GET" )
        taskqueue.add(queue_name='cache', url='/q/update_user_cache', params={'tk':token.key(), 'screen_name':screen_name}, method="GET" )

        if 'error' in ruser:
            self.write(json.dumps({
                'success':False,
                'info':ruser['error'],
            }))
        else:
            self.write(json.dumps({
                'success':True,
                'info':'OK',
                'user':ruser,
            }))
Пример #5
0
    def post(self,screen_name, slug):
        token = md.get_default_access_token()
        if not token:
            self.write(json.dumps({
                'success':False,
                'info':'No access token avaliable.',
            }))
            return

        td = Twitdao(token)
        fuser=None
        if 'make' == slug:
            fuser = td.friendships_create(screen_name = screen_name)
        else:
            fuser = td.friendships_destroy(screen_name = screen_name)
        taskqueue.add(queue_name='cache', url='/q/update_user_cache', params={'tk':token.key(), 'user_id':token.user_id}, method="GET" )
        taskqueue.add(queue_name='cache', url='/q/update_user_cache', params={'tk':token.key(), 'screen_name':screen_name}, method="GET" )

        if 'error' in fuser:
            self.write(json.dumps({
                'success':False,
                'info':fuser['error'],
            }))
        else:
            self.write(json.dumps({
                'success':True,
                'info':'OK',
                'user':fuser,
            }))
Пример #6
0
    def get(self):
        user_id = self.param('user_id')

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

        td = Twitdao(token)
        token_user = td.users_show_by_id(user_id = token.user_id)
        owner_user = token_user

        res=td.hacked_follows_in_common_with(user_id)
        tweets=self.render('ajax/follows_in_common_with.html', {
            'token':token,
            'token_user':token_user,
            'owner_user':owner_user,
            'res':res,
        },out=False)

        self.write(json.dumps({
            'success':True,
            'info':'OK',
            'html':tweets,
        }))
Пример #7
0
    def get(self, screen_name, slug):
        params = self.params(["since_id", "max_id", "per_page", "page", "include_entities"])

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        token_user = td.users_show_by_id(user_id=token.user_id)
        owner_user = td.users_show_by_screen_name(screen_name=screen_name)
        ls = td.user_list_id_get(id=slug, screen_name=screen_name)
        timeline = td.user_list_id_statuses(id=slug, screen_name=screen_name, **params)

        self.render(
            "list-timeline.html",
            {
                "token": token,
                "token_user": token_user,
                "owner_user": owner_user,
                "list": ls,
                "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": "list-timeline",
            },
        )
Пример #8
0
    def post(self):
        status = self.param('status')
        
        params = self.params([
            'in_reply_to_status_id',
            'lat',
            'long',
            'place_id',
            'display_coordinates',
            '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)
        tweet = td.statuses_update(status=status.encode('utf-8'), **params)
        taskqueue.add(queue_name='cache', url='/q/update_user_cache', params={'tk':token.key(), 'user_id':token.user_id}, method="GET" )
        self.write(json.dumps({
            'success':'error' not in tweet,
            'info':tweet['error'] if 'error' in tweet else 'OK',
            'tweet':tweet if 'error' not in tweet else None,
        }))
Пример #9
0
    def get(self):

        screen_name = self.param("screen_name")
        status_id = self.param("status_id")

        params = self.params(["trim_user", "include_entities"])

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        if screen_name:
            td = Twitdao(token)
            token_user = td.users_show_by_id(user_id=token.user_id)
            owner_user = token_user

            self.render(
                "reply.html",
                {"token": token, "token_user": token_user, "owner_user": owner_user, "screen_name": screen_name},
            )
        else:
            td = Twitdao(token)
            token_user = td.users_show_by_id(user_id=token.user_id)
            owner_user = token_user
            tweet = td.statuses_show(id=status_id, **params)

            self.render(
                "reply.html", {"token": token, "token_user": token_user, "owner_user": owner_user, "tweet": tweet}
            )
Пример #10
0
    def get(self, screen_name):

        params = self.params(["user_id", "cursor", "include_entities"], cursor=-1)

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        token_user = td.users_show_by_id(user_id=token.user_id)
        owner_user = td.users_show_by_screen_name(screen_name=screen_name)
        following = td.statuses_friends(screen_name=screen_name, **params)

        self.render(
            "following.html",
            {
                "token": token,
                "token_user": token_user,
                "owner_user": owner_user,
                "error": following["error"] if "error" in following else False,
                "following": following if "error" in following else following["users"],
                "next_cursor": None if "error" in following else following["next_cursor"],
                "next_cursor_str": None if "error" in following else following["next_cursor_str"],
                "previous_cursor": None if "error" in following else following["previous_cursor"],
                "previous_cursor_str": None if "error" in following else following["previous_cursor_str"],
                "where": "following",
            },
        )
Пример #11
0
    def get(self):
        q = self.param("q")
        page = self.param("page")

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        token_user = td.users_show_by_id(user_id=token.user_id)
        owner_user = token_user

        searchd = None
        timeline = []
        if q:
            searchd = td.hacked_search(q.encode("utf-8"), page=page)
            timeline = searchd["statuses"]
        self.render(
            "hacked_search.html",
            {
                "token": token,
                "token_user": token_user,
                "owner_user": owner_user,
                "q": q,
                "since_id": timeline[0]["id_str"] if type(timeline) == list and len(timeline) > 0 else None,
                "search_data": searchd,
            },
        )
Пример #12
0
    def get(self, screen_name):

        params = self.params(
            ["user_id", "since_id", "max_id", "count", "page", "trim_user", "include_rts", "include_entities"],
            include_rts="true",
        )

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        owner_user = td.users_show_by_screen_name(screen_name=screen_name)
        token_user = td.users_show_by_id(user_id=token.user_id)
        friendship = td.friendships_show(source_id=token.user_id, target_screen_name=screen_name)
        timeline = td.user_timeline(screen_name=screen_name, **params)

        self.render(
            "user-timeline.html",
            {
                "token": token,
                "token_user": token_user,
                "owner_user": owner_user,
                "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,
                "timeline": timeline,
                "friendship": friendship,
                "where": "user",
            },
        )
Пример #13
0
    def get(self, id):
        params = self.params(['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)
        token_user = td.users_show_by_id(user_id = token.user_id)
        tweet = td.statuses_show(id=id, **params)
        tweet_html = self.render('ajax/user-tweet.html', {
            'token':token,
            #'token_user':token_user,
            'tweet':tweet,
        }, out=False)

        self.write(json.dumps({
            'tweet':tweet_html if 'error' not in tweet else None,
            'success':'error' not in tweet,
            'info':tweet['error'] if 'error' in tweet else 'OK',
        }))
Пример #14
0
    def get(self):

        q = self.param("q")

        params = self.params(
            ["lang", "locate", "rpp", "page", "since_id", "until", "geocode", "show_user", "result_type"]
        )

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        token_user = td.users_show_by_id(user_id=token.user_id)
        owner_user = token_user
        limit_rate = td.API_limit_rate()

        searchd = None
        if q:
            q = q.encode("utf-8")
            searchd = td.search(q, **params)
        self.render(
            "search.html",
            {
                "token": token,
                "token_user": token_user,
                "owner_user": owner_user,
                "q": q,
                "limit_rate": limit_rate,
                "search_data": searchd,
            },
        )
Пример #15
0
    def get(self, tweet_id):

        params = self.params([
            'count',
            'page',
            'trim_user',
            'include_entities'
        ], include_entities='0')
        #default count number is 20.

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

        td = Twitdao(token)
        token_user = td.users_show_by_id(user_id = token.user_id)
        owner_user = token_user
        users = td.statuses_retweeted_by(id=tweet_id, **params)

        retweeted_by = self.render('ajax/retweeted-by.html', {
            'token':token,
            'token_user':token_user,
            'owner_user':owner_user,
            'users':users,
        },out=False)

        self.write(json.dumps({
            'success':True,
            'info':'OK',
            'retweeted_by':retweeted_by,
        }))
Пример #16
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,
            },
        )
Пример #17
0
    def get(self, screen_name):

        params = self.params(["cursor"], cursor=-1)

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        token_user = td.users_show_by_id(user_id=token.user_id)
        owner_user = td.users_show_by_screen_name(screen_name=screen_name)
        lists = td.user_list_subscriptions(screen_name=screen_name, **params)

        self.render(
            "lists-subscriptions.html",
            {
                "token": token,
                "token_user": token_user,
                "owner_user": owner_user,
                "lists": lists["lists"],
                "next_cursor": lists["next_cursor"],
                "next_cursor_str": lists["next_cursor_str"],
                "previous_cursor": lists["previous_cursor"],
                "previous_cursor_str": lists["previous_cursor_str"],
                "where": "list-subscriptions",
            },
        )
Пример #18
0
    def get(self, screen_name):

        params = self.params(["cursor"], cursor=-1)

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        token_user = td.users_show_by_id(user_id=token.user_id)
        owner_user = td.users_show_by_screen_name(screen_name=screen_name)
        add_user = owner_user
        lists = td.user_lists_get(**params)

        self.render(
            "lists-add-to.html",
            {
                "token": token,
                "token_user": token_user,
                "owner_user": owner_user,
                "add_user": add_user,
                "lists": lists["lists"],
                "where": "lists",
            },
        )
Пример #19
0
    def get(self):
        denied = self.param('denied', default_value=None)

        if denied:
            self.render('denied.html')
            return

        oauth_verifier = self.param('oauth_verifier')
        cookie_id = self.get_cookie('cid','')
        request_token = memcache.get(cookie_id)

        if not request_token or 'oauth_token' not in request_token:
            self.delete_cookie('cid')
            self.error(404)
            return

        td = Twitdao(md.AccessToken(
            oauth_token=request_token['oauth_token'],
            oauth_token_secret=request_token['oauth_token_secret']
        ))

        access_token = td.fetch_access_token(oauth_verifier)

        md.save_access_token(
            user_id=access_token['user_id'],
            screen_name=access_token['screen_name'],
            oauth_token=access_token['oauth_token'],
            oauth_token_secret=access_token['oauth_token_secret'],
            app_user = users.get_current_user()
        )

        self.delete_cookie('cid')
        self.redirect(self.param('url'))
Пример #20
0
    def post(self):
        tk=self.param('tk')
        if not tk:
            self.error(404)
            return

        ds_type=self.param('ds_type')

        token = md.get_access_token(tk, users.get_current_user())
        if not token:
            self.redirect('/settings')
            return

        td=Twitdao(token)
        if ds_type == 'colors':
            params=self.params([
                'profile_background_color',
                'profile_text_color',
                'profile_link_color',
                'profile_sidebar_fill_color',
                'profile_sidebar_border_color',
                'include_entities',
            ])
            td.account_update_profile_colors(**params)
        elif ds_type == 'background':
            image=self.param('image')
            if image:
                params=self.params(['tile','include_entities'])
                for k in params:
                    params[k]=params[k].encode('utf-8')
                filename=self.request.POST[u'image'].filename.encode('utf-8')
                td.account_update_profile_background_image(('image', filename, image), **params)

        self.redirect('/settings/design?tk=%s' % tk)
Пример #21
0
    def post(self):
        tk=self.param('tk')
        if not tk:
            self.error(404)
            return


        token = md.get_access_token(tk, users.get_current_user())
        if not token:
            self.redirect('/settings')
            return

        td=Twitdao(token)
        
        image=self.param('picture')
        if image:
            filename=self.request.POST[u'picture'].filename.encode('utf-8')
            td.account_update_profile_image(('image', filename, image))

        params=self.params(['name', 'url', 'location', 'description', 'include_entities'])
        for k in params:
            params[k]=params[k].encode('utf-8')
        td.account_update_profile(**params)

        self.redirect('/settings/profile?tk=%s' % tk)
Пример #22
0
    def get(self):
        params = self.params(["since_id", "max_id", "count", "page", "trim_user", "include_rts", "include_entities"])

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        token_user = td.users_show_by_id(user_id=token.user_id)
        owner_user = token_user
        timeline = td.mentions(**params)

        self.render(
            "mentions-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": "mentions",
            },
        )
Пример #23
0
    def get(self, screen_name, slug):

        params = self.params(["cursor", "include_entities"], cursor=-1)

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        token_user = td.users_show_by_id(user_id=token.user_id)
        owner_user = td.users_show_by_screen_name(screen_name=screen_name)
        lst = td.user_list_id_get(id=slug, screen_name=screen_name)
        followers = td.user_list_id_subscribers_get(screen_name, slug, **params)
        self.render(
            "list-followers.html",
            {
                "token": token,
                "token_user": token_user,
                "owner_user": owner_user,
                "error": followers["error"] if "error" in followers else False,
                "followers": followers if "error" in followers else followers["users"],
                "next_cursor": None if "error" in followers else followers["next_cursor"],
                "next_cursor_str": None if "error" in followers else followers["next_cursor_str"],
                "previous_cursor": None if "error" in followers else followers["previous_cursor"],
                "previous_cursor_str": None if "error" in followers else followers["previous_cursor_str"],
                "list": lst,
                "where": "list-followers",
            },
        )
Пример #24
0
    def get(self):

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

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        token_user = td.users_show_by_id(user_id=token.user_id)
        owner_user = token_user
        direct_messages = td.direct_messages_sent(**params)
        self.render(
            "messages-sent.html",
            {
                "token": token,
                "token_user": token_user,
                "owner_user": owner_user,
                "max_id": str(direct_messages[-1]["id"] - 1)
                if type(direct_messages) == list and len(direct_messages) > 0
                else None,
                "since_id": direct_messages[0]["id_str"]
                if type(direct_messages) == list and len(direct_messages) > 0
                else None,
                "messages": direct_messages,
                "where": "sent",
            },
        )
Пример #25
0
    def get(self):
        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        params = self.params(["page", "include_entities"])
        page = self.param("page")

        td = Twitdao(token)
        token_user = td.users_show_by_id(user_id=token.user_id)
        owner_user = token_user
        blocking = td.blocks_blocking(**params)

        prev_page, next_page = None, 2
        if page:
            try:
                page = int(page)
                prev_page = page - 1 if page - 1 > 0 else None
                next_page = page + 1
            except:
                pass

        self.render(
            "blocking.html",
            {
                "token_user": token_user,
                "owner_user": owner_user,
                "blocking": blocking,
                "prev_page": prev_page,
                "next_page": next_page,
            },
        )
Пример #26
0
 def get(self):
     token = md.get_default_access_token()
     if not token:
         self.redirect("/settings")
         return
     td = Twitdao(token)
     token_user = td.users_show_by_id(user_id=token.user_id)
     owner_user = token_user
     self.render("mobile/upload.html", {"token": token, "token_user": token_user, "owner_user": owner_user})
Пример #27
0
    def post(self, screen_name, slug):

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        td.user_list_id_subscribers_delete(screen_name=screen_name, list_id=slug)
        self.redirect("/t/%s/%s" % (screen_name, slug))
Пример #28
0
    def post(self, lid):

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        lst = td.user_list_id_delete(id=lid)
        self.redirect("/t/%s/lists" % token.screen_name)
Пример #29
0
    def post(self, slug, screen_name):

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        td.user_list_id_members_delete(screen_name=token.screen_name, list_id=slug, id=screen_name)
        self.redirect("/t/%s/%s/following" % (token.screen_name, slug))
Пример #30
0
    def post(self, id):
        params = self.params(["include_entities"])

        token = md.get_default_access_token()
        if not token:
            self.redirect("/settings")
            return

        td = Twitdao(token)
        message = td.direct_messages_destroy(id=id, **params)
        self.redirect("/a/messages_sent")