예제 #1
0
파일: update.py 프로젝트: alphazw/moedj
class SendItem(object):
    def __init__(self):
        super(SendItem, self).__init__()
        prefix, self.ItemTobeSendKey = getItemTobeSend()
        if not self.ItemTobeSendKey:
            setattr(self, 'ItemTobeSend', None)
            logger.info("No item to be send")
            return None
        self.ItemTobeSend = self.ItemTobeSendKey.partition(prefix)[2]
        self.getWeiboApi()

    def getWeiboApi(self):
        AuthInfo = WeiboAuthInfoRedis("original")
        token = rs.hgetall("WeiboAuth"+"original")
        self.weiboApi = WeiboApi(
            MPConf.SinaAppKey,
            MPConf.SinaAppSecret,
            MPConf.Domain+'/sinacallback',
            token['access_token'],
            token['expires_in'])


    def prepare(self):
        """
        format weibo content
        """
        weiboTitle = self.ItemTobeSend
        last_editor = get_last_editor_name(self.ItemTobeSend)

        self.weibo_content = weiboTitle.decode('utf-8')
        self.weibo_link = "http://zh.moegirl.org/" + \
                    urllib.quote(weiboTitle)
        self.img = getImage(self.weibo_link)

    def sendRoutine(self):
        if not self.ItemTobeSend:
            return None
        try:
            self.prepare()
            self.send()
            logger.info("Sending: "+self.ItemTobeSend+" Succ")
        except:
            logger.info(traceback.format_exc())
        finally:
            self.postsend()

    def send(self):
        try:
            self.weiboApi.send(self.weibo_content, self.weibo_link, self.img)
        except APIError as e:
            if 'expired_token' in e:
                logger.info("Sina Weibo Token已到期,请重新授权")

    def postsend(self):
        key = SENT + self.ItemTobeSend
        rs.set(key, self.ItemTobeSend, SENT_EXPIRE)
        rs.delete(self.ItemTobeSendKey)
예제 #2
0
class SendItem(object):
    def __init__(self):
        super(SendItem, self).__init__()
        prefix, self.ItemTobeSendKey = getItemTobeSend()
        if not self.ItemTobeSendKey:
            setattr(self, 'ItemTobeSend', None)
            logger.info("No item to be send")
            return None
        self.ItemTobeSend = self.ItemTobeSendKey.partition(prefix)[2]
        self.getWeiboApi()

    def getWeiboApi(self):
        AuthInfo = WeiboAuthInfoRedis("original")
        token = rs.hgetall("WeiboAuth" + "original")
        self.weiboApi = WeiboApi(MPConf.SinaAppKey, MPConf.SinaAppSecret,
                                 MPConf.Domain + '/sinacallback',
                                 token['access_token'], token['expires_in'])

    def prepare(self):
        """
        format weibo content
        """
        weiboTitle = self.ItemTobeSend
        last_editor = get_last_editor_name(self.ItemTobeSend)

        self.weibo_content = weiboTitle.decode('utf-8')
        self.weibo_link = "http://zh.moegirl.org/" + \
                    urllib.quote(weiboTitle)
        self.img = getImage(self.weibo_link)

    def sendRoutine(self):
        if not self.ItemTobeSend:
            return None
        try:
            self.prepare()
            self.send()
            logger.info("Sending: " + self.ItemTobeSend + " Succ")
        except:
            logger.info(traceback.format_exc())
        finally:
            self.postsend()

    def send(self):
        try:
            self.weiboApi.send(self.weibo_content, self.weibo_link, self.img)
        except APIError as e:
            if 'expired_token' in e:
                logger.info("Sina Weibo Token已到期,请重新授权")

    def postsend(self):
        key = SENT + self.ItemTobeSend
        rs.set(key, self.ItemTobeSend, SENT_EXPIRE)
        rs.delete(self.ItemTobeSendKey)
예제 #3
0
파일: update.py 프로젝트: alphazw/moedj
 def getWeiboApi(self):
     AuthInfo = WeiboAuthInfoRedis("original")
     token = rs.hgetall("WeiboAuth"+"original")
     self.weiboApi = WeiboApi(
         MPConf.SinaAppKey,
         MPConf.SinaAppSecret,
         MPConf.Domain+'/sinacallback',
         token['access_token'],
         token['expires_in'])
예제 #4
0
 def getWeiboApi(self):
     AuthInfo = WeiboAuthInfoRedis("original")
     token = rs.hgetall("WeiboAuth" + "original")
     self.weiboApi = WeiboApi(MPConf.SinaAppKey, MPConf.SinaAppSecret,
                              MPConf.Domain + '/sinacallback',
                              token['access_token'], token['expires_in'])