Example #1
0
def sendQQWeibo(self,text,imgno=None):
    userAccessToken=UserAccessToken().all().fetch(1) 
    if userAccessToken and userAccessToken[0].qqisright:
        useracc=userAccessToken[0]
    else:
        return True
    self.auth = qqOAuthHandler(webSetting.qqconsumer_key, webSetting.qqconsumer_secret)
    self.auth.setToken(useracc.qqToken, useracc.qqSecret)
    self.api = qqAPI(self.auth)



    try:
        if imgno:
#                image = urlfetch.fetch(
#                    url =setting[0].dbphotoWebSite+'/s/'+imgno,
#                    payload = {},
#                    method = urlfetch.GET,
#                    headers = {'Content-Type':'application/x-www-form-urlencoded',
#                               'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6'},
#                    follow_redirects = True,deadline=10)
#                if image.status_code==200:
#                    bf=db.Blob(image.content)
            result=self.api._t_add_pic(filename=imgno,content=text.encode('utf-8'),clientip='64.233.172.33')
#                else:
#                    result=self.api.update_status(status=text[:139].encode('utf-8'))
        else:
            result=self.api._t_add(content=text.encode('utf-8'),clientip='64.233.172.33')
    except Exception,e:
        logging.info('qq'+str(e))
        if str(e).find('40025')==-1:
            self.error(500)
            return False
Example #2
0
def sendQQWeibo(request,text,imgno=None):
    weiboquery=WeiBo.objects.filter(user=request.user).filter(type="teng")
    if 0==weiboquery.count():
        return True
    weibo=weiboquery[0]
    auth = qqOAuthHandler(qqconsumer_key, qqconsumer_secret)
    auth.setToken(weibo.token1, weibo.token0)
    api = qqAPI(auth)



    try:
        if imgno:
#                image = urlfetch.fetch(
#                    url =setting[0].dbphotoWebSite+'/s/'+imgno,
#                    payload = {},
#                    method = urlfetch.GET,
#                    headers = {'Content-Type':'application/x-www-form-urlencoded',
#                               'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6'},
#                    follow_redirects = True,deadline=10)
#                if image.status_code==200:
#                    bf=db.Blob(image.content)
            result=api._t_add_pic(filename=imgno,content=text.encode('utf-8'),clientip='64.233.172.33')
#                else:
#                    result=self.api.update_status(status=text[:139].encode('utf-8'))
        else:
            result=api._t_add(content=text.encode('utf-8'),clientip='64.233.172.33')
    except Exception,e:
        logging.info('qq'+str(e))
        if str(e).find('40025')==-1:
            return False