def __init__(self, token=None): self.token = token config = md.get_app_config() if token: self.twitter = Twitter( oauth_token=self.token.oauth_token, oauth_token_secret=self.token.oauth_token_secret, consumer_key=config.consumer_key, consumer_secret=config.consumer_secret, request_token_url=config.request_token_url, access_token_url=config.access_token_url, authorize_url=config.authorize_url, authenticate_url=config.authenticate_url, api_url=config.api_url, search_api_url=config.search_api_url ) else: self.twitter = Twitter( consumer_key=config.consumer_key, consumer_secret=config.consumer_secret, request_token_url=config.request_token_url, access_token_url=config.access_token_url, authorize_url=config.authorize_url, authenticate_url=config.authenticate_url, api_url=config.api_url, search_api_url=config.search_api_url )
def get(self): app_config = None if users.is_current_user_admin(): app_config = md.get_app_config() self.render('app-config.html', { 'app_config':app_config, 'where':'twitdao-config' })
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)
def post(self): media = self.param('media') token = md.get_default_access_token() if not token: self.write(json.dumps({ 'success':False, 'info':'No access token avaliable.', })) 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':''}, files=[('media', filename, media)]) self.write(json.dumps({ 'success':'id' in resp, 'info':'OK', 'response':resp, })) except Exception, e: self.write(json.dumps({ 'success':False, 'info':str(e), 'response':None, }))