Exemple #1
0
    def Get_DBctrl_Twitter(self):
        #############################
        # DB接続
        wOBJ_DB = CLS_PostgreSQL_Use(gVal.DEF_STR_FILE['DBinfo_File'])
        wRes = wOBJ_DB.GetIniStatus()
        if wRes['Result'] != True:
            ##失敗
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_TwitterReader: Get_DBctrl_Twitter: DB Connect test is failed: "
                + wRes['Reason'])
            wOBJ_DB.Close()
            return

        #############################
        # 取り出し
        wQuery = "select * from TBL_TWITTER_READER ;"

        wRes = wOBJ_DB.RunQuery(wQuery)
        wRes = wOBJ_DB.GetQueryStat()
        if wRes['Result'] != True:
            ##失敗
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_TwitterReader: Get_DBctrl_Twitter: Run Query is failed: "
                + wRes['Reason'] + " query=" + wRes['Query'])
            wOBJ_DB.Close()
            return

        if len(wRes['Responce']['Data']) == 0:
            ##トレンド情報なし
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_TwitterReader: Get_DBctrl_Twitter: TBL_TWITTER_READER record is 0"
            )
            wOBJ_DB.Close()
            return

        #############################
        # 一回ローカルに読み出す
        wARR_Twitter = {}
        wIndex = 0
        for wLineTap in wRes['Responce']['Data']:
            ##領域の準備
            wARR_Twitter.update({wIndex: ""})
            wARR_Twitter[wIndex] = {}
            wARR_Twitter[wIndex].update({"id": 0})
            wARR_Twitter[wIndex].update({"text": ""})
            wARR_Twitter[wIndex].update({"screen_name": ""})
            wARR_Twitter[wIndex].update({"send_user": ""})
            wARR_Twitter[wIndex].update({"tags": ""})
            wARR_Twitter[wIndex].update({"lupdate": ""})
            wARR_Twitter[wIndex].update({"sended": False})

            ##取り出し
            wGetTap = []
            for wCel in wLineTap:
                wGetTap.append(wCel)
                ## [0] ..id
                ## [1] ..text
                ## [2] ..screen_name
                ## [3] ..send_user
                ## [4] ..tags
                ## [5] ..lupdate
                ## [6] ..sended

            ##領域へロード
            wARR_Twitter[wIndex]['id'] = int(wGetTap[0])
            wARR_Twitter[wIndex]['text'] = wGetTap[1].strip()
            wARR_Twitter[wIndex]['screen_name'] = wGetTap[2].strip()
            wARR_Twitter[wIndex]['send_user'] = wGetTap[3].strip()
            wARR_Twitter[wIndex]['lupdate'] = wGetTap[5]
            wARR_Twitter[wIndex]['sended'] = wGetTap[6]

            wGetTap[4] = wGetTap[4].strip()
            if wGetTap[4] == "(none)":
                wGetTap[4] = ""  # null設定
            wARR_Twitter[wIndex]['tags'] = wGetTap[4]

            wIndex += 1

        #############################
        # DB切断
        wOBJ_DB.Close()

        #############################
        # 未送信のものを読みだす
        self.ARR_Twitter = {}

        wKeylist = wARR_Twitter.keys()
        wIndex = 0
        for wKey in wKeylist:
            if wARR_Twitter[wKey]['sended'] == True:
                continue  #送信済
            if wARR_Twitter[wKey]['send_user'] != self.Obj_Parent.CHR_Account:
                continue  #送信者ではない

            #############################
            # 格納
            self.ARR_Twitter.update({wIndex: ""})
            self.ARR_Twitter[wIndex] = {}
            self.ARR_Twitter[wIndex].update({"id": wARR_Twitter[wKey]['id']})
            self.ARR_Twitter[wIndex].update(
                {"text": wARR_Twitter[wKey]['text']})
            self.ARR_Twitter[wIndex].update(
                {"screen_name": wARR_Twitter[wKey]['screen_name']})
            self.ARR_Twitter[wIndex].update(
                {"send_user": wARR_Twitter[wKey]['send_user']})
            self.ARR_Twitter[wIndex].update(
                {"tags": wARR_Twitter[wKey]['tags']})
            self.ARR_Twitter[wIndex].update(
                {"lupdate": wARR_Twitter[wKey]['lupdate']})
            self.ARR_Twitter[wIndex].update({"sended": False})
            wIndex += 1

        return
Exemple #2
0
    def Delete_DBctrl_Twitter(self):
        #############################
        # DB接続
        wOBJ_DB = CLS_PostgreSQL_Use(gVal.DEF_STR_FILE['DBinfo_File'])
        wRes = wOBJ_DB.GetIniStatus()
        if wRes['Result'] != True:
            ##失敗
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_TwitterReader: Delete_DBctrl_Twitter: DB Connect test is failed: "
                + wRes['Reason'])
            wOBJ_DB.Close()
            return

        #############################
        # 削除対象レコード数
        wQuery = "select * from TBL_TWITTER_READER where sended = True ;"
        wDBRes = wOBJ_DB.RunQuery(wQuery)
        wDBRes = wOBJ_DB.GetQueryStat()
        if wDBRes['Result'] != True:
            ##失敗
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_TwitterReader: Delete_DBctrl_Twitter: Run Query is failed: "
                + wDBRes['Reason'] + " query=" + wDBRes['Query'])
            wOBJ_DB.Close()
            return False

        wDeleteNum = len(wDBRes['Responce']['Data'])

        #############################
        # 削除
        wQuery = "delete from TBL_TWITTER_READER where " + \
           "sended = True " + \
           ";"

        #############################
        # クエリ実行
        wDBRes = wOBJ_DB.RunQuery(wQuery)
        wDBRes = wOBJ_DB.GetQueryStat()
        if wDBRes['Result'] != True:
            ##失敗
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_TwitterReader: Delete_DBctrl_Twitter: DB insert is failed: "
                + wDBRes['Reason'] + " query=" + wDBRes['Query'])
            wOBJ_DB.Close()
            return

        self.STR_Cope['Delete'] += wDeleteNum
        #############################
        # DB切断
        wOBJ_DB.Close()

        return
Exemple #3
0
    def Set_DBctrl_Twitter(self):
        #############################
        # DB接続
        wOBJ_DB = CLS_PostgreSQL_Use(gVal.DEF_STR_FILE['DBinfo_File'])
        wRes = wOBJ_DB.GetIniStatus()
        if wRes['Result'] != True:
            ##失敗
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_TwitterReader: Set_DBctrl_Twitter: DB Connect test is failed: "
                + wRes['Reason'])
            wOBJ_DB.Close()
            return

        wKeyList = self.ARR_Twitter.keys()
        #############################
        # ダブりがないかチェック
        # ・なければ追加
        # ・あれば更新
        for wKey in wKeyList:
            wQuery = "select * from TBL_TWITTER_READER where id = '" + self.ARR_Twitter[
                wKey]['id'] + "' ;"
            wDBRes = wOBJ_DB.RunQuery(wQuery)
            wDBRes = wOBJ_DB.GetQueryStat()
            if wDBRes['Result'] != True:
                ##失敗
                self.Obj_Parent.OBJ_Mylog.Log(
                    'a',
                    "CLS_TwitterReader: Set_DBctrl_Twitter: Run Query is failed: "
                    + wDBRes['Reason'] + " query=" + wDBRes['Query'])
                wOBJ_DB.Close()
                return False

            wFLG_Update = False
            wText = str(self.ARR_Twitter[wKey]['text']).replace("'", "''")
            #############################
            # クエリの作成
            if self.ARR_Twitter[wKey]['tags'] == "":
                self.ARR_Twitter[wKey]['tags'] = "(none)"  # SQL用補完

            ###なければ追加
            if len(wDBRes['Responce']['Data']) == 0:
                wQuery = "insert into TBL_TWITTER_READER values (" + \
                   str( self.ARR_Twitter[wKey]['id'] ) + "," + \
                   "'" + wText + "'," + \
                   "'" + self.ARR_Twitter[wKey]['screen_name'] + "'," + \
                   "'" + self.ARR_Twitter[wKey]['send_user'] + "'," + \
                   "'" + self.ARR_Twitter[wKey]['tags'] + "'," + \
                   "'" + self.ARR_Twitter[wKey]['lupdate'] + "'," + \
                   str( self.ARR_Twitter[wKey]['sended'] ) + " " + \
                   ") ;"

            ###あれば更新
            else:
                wChgList = []
                if wOBJ_DB.ChgList(wDBRes['Responce']['Data'],
                                   outList=wChgList) != True:
                    ##ないケースかも
                    self.Obj_Parent.OBJ_Mylog.Log(
                        'a', "CLS_UserCorr: AddUser: Select data is Zero")
                    wOBJ_DB.Close()
                    return False
                wChgList = wChgList[0]  #1行しかないし切る

                wQuery = "update TBL_TWITTER_READER set " + \
                  "text = '" + wText + "', " + \
                  "screen_name = '" + str(self.ARR_Twitter[wKey]['screen_name']) + "', " + \
                  "send_user = '******'send_user']) + "', " + \
                  "tags = '"    + str(self.ARR_Twitter[wKey]['tags']) + "', " + \
                  "lupdate = '" + str(self.ARR_Twitter[wKey]['lupdate']) + "', " + \
                  "sended = "   + str(self.ARR_Twitter[wKey]['sended']) + " " + \
                  "where id = '" + wChgList[0] + "' ;"

                wFLG_Update = True

            #############################
            # クエリ実行
            wDBRes = wOBJ_DB.RunQuery(wQuery)
            wDBRes = wOBJ_DB.GetQueryStat()
            if wDBRes['Result'] != True:
                ##失敗
                self.Obj_Parent.OBJ_Mylog.Log(
                    'a', "CLS_UserCorr: AddUser: DB insert is failed: " +
                    wDBRes['Reason'] + " query=" + wDBRes['Query'])
                wOBJ_DB.Close()
                return False

            #############################
            # カウント
            if wFLG_Update == True:
                self.STR_Cope['Update'] += 1
            else:
                self.STR_Cope['Insert'] += 1

        #############################
        # 正常終了
        wOBJ_DB.Close()
        return