コード例 #1
0
ファイル: ajax.py プロジェクト: messiahxu/Twitdao11
    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,
        }))
コード例 #2
0
ファイル: main.py プロジェクト: tongsu/twitdao
    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.redirect("/settings")
            return
        td = Twitdao(token)
        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.redirect("/t")
コード例 #3
0
ファイル: mobile.py プロジェクト: tongsu/twitdao
    def post(self):
        media = self.param("media")
        status = self.param("status")

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

        app_config = md.get_app_config()
        td = Twitdao(token)
        twitpic = twitpic2.TwitPic2(
            consumer_key=app_config.consumer_key,
            consumer_secret=app_config.consumer_secret,
            access_token="oauth_token=%s&oauth_token_secret=%s" % (token.oauth_token, token.oauth_token_secret),
            service_key=app_config.twitpic_api_key,
        )

        try:
            if media:
                filename = self.request.POST[u"media"].filename.encode("utf-8")
                resp = twitpic.api_call(
                    "POST", "upload", {"message": status.encode("utf-8")}, files=[("media", filename, media)]
                )
            full_status = status + " " + resp["url"]
            tweet_status = full_status
            if len(full_status) - 140 > 0:
                tweet_status = status[: 140 - len(resp["url"]) - 4] + "... " + resp["url"]
            td.statuses_update(status=tweet_status.encode("utf-8"))
            taskqueue.add(
                queue_name="cache",
                url="/q/update_user_cache",
                params={"tk": token.key(), "user_id": token.user_id},
                method="GET",
            )
        except Exception, e:
            logging.debug(e)