Beispiel #1
0
    def TwitterBoost(self, inID, inFulluser, inCont, inTwitterTags):
        if len(inCont) <= 0:
            ###ありえない
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_LookHTL: TwitterBoost: Content size is zero")
            return False

        #############################
        # Twitterタグ
        wTwitterTags = ""
        if inTwitterTags != "":
            wARR_TwitterTags = inTwitterTags.split(",")
            for wLine in wARR_TwitterTags:
                wTwitterTags = wTwitterTags + " #" + wLine

        #############################
        # ツイートの組み立て
        ### ファボられたトゥートURL
        wToot_Url = " https://" + inFulluser['Domain'] + "/@" + inFulluser[
            'Username'] + "/" + str(inID)

        ### 頭とトゥートURLを抜いた文字数
        ##		wMAX_Tweet = 140 - len( wToot_Url )
        wMAX_Tweet = 140 - len(wToot_Url) - len(wTwitterTags)
        if wMAX_Tweet <= 0:
            ###ありえない
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_LookHTL: TwitterBoost: Tweet Header size is zero")
            return False

        ### 本文の短縮化
        wCHR_Body = inCont

        wCHR_Body = wCHR_Body.replace('\n', '')
        wIndex = inCont.find("#")
        wCHR_Body = wCHR_Body[0:wIndex]
        wCHR_Body = wCHR_Body.strip()
        wCHR_Body = CLS_OSIF.sDel_URL(wCHR_Body)  #URLを除去

        # 読点で140字に収まるまで切る
        wARR_Body = wCHR_Body.split("。")
        wNew_Body = ""
        if len(wARR_Body) > 2:
            for wLine in wARR_Body:
                if wLine == "":
                    break  #最終桁
                wLine = wLine + "。"  #最初に読点補完
                wComp = wNew_Body + wLine
                if len(wComp) > wMAX_Tweet:
                    break  #140字超えた
                wNew_Body = wNew_Body + wLine
            wCHR_Body = wNew_Body
        else:
            wCHR_Body = wCHR_Body[0:wMAX_Tweet]

##		wCHR_Tweet = wCHR_Body + wToot_Url
        wCHR_Tweet = wCHR_Body + wTwitterTags + wToot_Url
        #############################
        # Twitterへ投稿
        wRes = self.Obj_Parent.OBJ_Twitter.Tweet(wCHR_Tweet)
        if wRes['Result'] != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_LookHTL: TwitterBoost: Mastodon error: " + wRes['Reason'])
            return False

        return True
Beispiel #2
0
    def Send_Toot(self):
        #############################
        # DB制御  取出
        self.Get_DBctrl_Twitter()

        #############################
        # 送信データなし
        wKeylist = self.ARR_Twitter.keys()
        if len(wKeylist) == 0:
            return

        #############################
        # 送信
        for wKey in wKeylist:
            #############################
            # トゥートの組み立て
            wCHR_Title = "Transfer from Twitter:" + '\n'

            wCHR_Body = ""
            ### Body
            wText = self.ARR_Twitter[wKey]['text'].replace('\n', '')
            wText = CLS_OSIF.sDel_URL(wText)  #URLを除去
            wCHR_Body = wCHR_Body + wText + '\n'

            ### Source: User / Timedate / URL
            wCHR_Body = wCHR_Body + "--[Source: " + str(
                self.ARR_Twitter[wKey]['lupdate']) + "]--" + '\n'
            wCHR_Body = wCHR_Body + "User: "******" "
            wCHR_Body = wCHR_Body + "https://twitter.com/" + self.ARR_Twitter[
                wKey]['screen_name'] + "/status/" + str(
                    self.ARR_Twitter[wKey]['id']) + '\n'

            ### add Tags
            wCHR_Tags = ""
            if self.ARR_Twitter[wKey]['tags'] != "":
                wARR_Tags = self.ARR_Twitter[wKey]['tags'].split(",")
                for wTag in wARR_Tags:
                    wCHR_Tags = wCHR_Tags + " #" + wTag

##			wCHR_Toot = wCHR_Title + wCHR_Body + "#" + gVal.STR_MasterConfig['TwitterReaderTag']
            wCHR_Toot = wCHR_Title + wCHR_Body + "#" + gVal.STR_MasterConfig[
                'TwitterReaderTag'] + wCHR_Tags

            #############################
            # トゥートの送信
            ##			wRes = self.Obj_Parent.OBJ_MyDon.Toot( status=wCHR_Toot, visibility=self.CHR_SendRange )
            wRes = self.Obj_Parent.OBJ_MyDon.Toot(
                status=wCHR_Toot, visibility=self.DEF_SENDRANGE)
            if wRes['Result'] != True:
                self.Obj_Parent.OBJ_Mylog.Log(
                    'a', "CLS_TwitterReader: Send_Trend: Mastodon error: " +
                    wRes['Reason'])
                return

            self.ARR_Twitter[wKey]['sended'] = True
            #############################
            # カウント
            self.STR_Cope['Sended'] += 1

        #############################
        # DB制御  送信済にチェック
        self.Sended_DBctrl_Twitter()
        return