Пример #1
0
    def GetOldUser(self, inARR_Follow):

        wARR_Users = []
        #############################
        # 指定日付の抽出
        wLag = gVal.DEF_STR_TLNUM['AutoRemoveDays'] * 24 * 60 * 60
        wLagTime = CLS_OSIF.sTimeLag(inThreshold=wLag, inTimezone=-1)
        if wLagTime['Result'] != True:
            ##失敗
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_UserCorr: GetOldUser: sTimeLag is failed")
            return wARR_Users

        #############################
        # 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_UserCorr: GetOldUser: DB Connect test is failed: " +
                wRes['Reason'])
            wOBJ_DB.Close()
            return wARR_Users

        #############################
        # 古いユーザ取得
        wQuery = "select id from TBL_USER_DATA where lupdate < " + \
           "timestamp '" + str(wLagTime['RateTime']) + "' " + \
           ";"
        wDBRes = wOBJ_DB.RunQuery(wQuery)
        wDBRes = wOBJ_DB.GetQueryStat()
        if wDBRes['Result'] != True:
            ##失敗
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_UserCorr: GetOldUser: Run Query is failed: " +
                wDBRes['Reason'] + " query=" + wDBRes['Query'])
            wOBJ_DB.Close()
            return wARR_Users

        #############################
        # 取得あればローカルに詰める
        wARR_OldUsers = []
        wOBJ_DB.ChgList(wDBRes['Responce']['Data'], outList=wARR_OldUsers)

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

        #############################
        # フォロー者のなかからリムーブ対象のユーザを出力
        for wUser in inARR_Follow:
            if wUser in wARR_OldUsers:
                wARR_Users.append(wUser)

        return wARR_Users
Пример #2
0
    def IsActiveUser(self, inFulluser):

        wARR_Users = []
        #############################
        # 指定日付の抽出
        wLag = gVal.DEF_STR_TLNUM['AutoRemoveDays'] * 24 * 60 * 60
        wLagTime = CLS_OSIF.sTimeLag(inThreshold=wLag, inTimezone=-1)
        if wLagTime['Result'] != True:
            ##失敗
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_UserCorr: IsActiveUser: sTimeLag is failed")
            return False

        #############################
        # 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_UserCorr: IsActiveUser: DB Connect test is failed: " +
                wRes['Reason'])
            wOBJ_DB.Close()
            return False

        #############################
        # 一定期間活動があるユーザか
##		wQuery = "id = '" + inFulluser + "' and " + \
##					"lupdate >= timestamp '" + str(wLagTime['RateTime']) + "'"
##
##		wDBRes = wOBJ_DB.RunExist( inObjTable="TBL_USER_DATA", inWhere=wQuery )
##		wDBRes = wOBJ_DB.GetQueryStat()
##		if wDBRes['Result']!=True :
##			##失敗
##			wRes['Reason'] = "CLS_UserCorr: IsActiveUser: Run Query is failed: " + wDBRes['Reason'] + " query=" + wDBRes['Query']
##			wOBJ_DB.Close()
##			return False
##
##		### 収集していないか、期間活動外
##		if wDBRes['Responce']==False :
##			wOBJ_DB.Close()
##			return False
##
        wQuery = "select locked from TBL_USER_DATA where " + \
           "id = '" + inFulluser + "' and " + \
           "lupdate >= timestamp '" + str(wLagTime['RateTime']) + "' " + \
           ";"

        wDBRes = wOBJ_DB.RunQuery(wQuery)
        wDBRes = wOBJ_DB.GetQueryStat()
        if wDBRes['Result'] != True:
            ##失敗
            wRes[
                'Reason'] = "CLS_UserCorr: IsActiveUser: Run Query is failed: " + wDBRes[
                    'Reason'] + " query=" + wDBRes['Query']
            wOBJ_DB.Close()
            return False

        ### 収集していないか、期間活動外
        if len(wDBRes['Responce']['Data']) == 0:
            wOBJ_DB.Close()
            return False

        ### 鍵垢か
        wChgList = []
        if wOBJ_DB.ChgList(wDBRes['Responce']['Data'],
                           outList=wChgList) != True:
            ##ないケースかも
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_UserCorr: IsActiveUser: Select data is Zero")
            wOBJ_DB.Close()
            return False
        if wChgList[0][0] == True:
            wOBJ_DB.Close()
            return False  #鍵つき

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

        ###有効なユーザ
        return True
Пример #3
0
    def AddUser(self, inROW, inUser):
        ##		wAccount = inROW['account']
        ##		#############################
        ##		# ユーザ名の変換
        ##		wFulluser = CLS_UserData.sGetFulluser( wAccount['username'], wAccount['url'] )
        ##		if wFulluser['Result']!=True :
        ##			###今のところ通らないルート
        ##			self.Obj_Parent.OBJ_Mylog.Log( 'a', "CLS_UserCorr: AddUser: sGetFulluser failed: " + wFulluser['Reason'] )
        ##			return False	#スルー

        #############################
        # 除外トゥート
        ##		###自分
        ##		if wFulluser['Fulluser'] == self.Obj_Parent.CHR_Account :
        ##			return False		#スルーする
        ##
        ##		###外人 (日本人限定=ON時)
        ##		if inROW['language']!="ja" and gVal.STR_MasterConfig["JPonly"]=="on" :
        ##			self.Obj_Parent.OBJ_Mylog.Log( 'c', "CLS_UserCorr: AddUser: 日本人以外を検出(登録除外): " + wFulluser['Fulluser'] )
        ##			return False		#スルーする
        ##
        ##		###除外ドメイン
        ##		if wFulluser['Domain'] in gVal.STR_DomainREM :
        ##			self.Obj_Parent.OBJ_Mylog.Log( 'c', "CLS_UserCorr: AddUser: 除外ドメインを検出(登録除外): " + wFulluser['Fulluser'] )
        ##			return False		#スルーする
        ##
        ###今回関わったユーザ
        if inUser['Fulluser'] in self.ARR_UpdateUser:
            return False  #スルーする
        self.ARR_UpdateUser.append(inUser['Fulluser'])

        # ここまでで登録処理確定
        #############################
        self.STR_Stat['Cope'] += 1

        #############################
        # postgreSQL対策で ' 文字を消す
        wResReplace = CLS_OSIF.sRe_Replace(
            "'", str(inROW['account']['display_name']), "''")
        ###	"Result"	: False,
        ###	"Match"		: False,
        ###	"After"		: None
        if wResReplace['Result'] != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_UserCorr: AddUser: sRe_Replace is failed: display_name=" +
                str(inROW['account']['display_name']))
            return False
        if wResReplace['Match'] == True:
            wDisplay_Name = wResReplace['After']
        else:
            wDisplay_Name = str(inROW['account']['display_name'])

        #############################
        # セット用領域の作成
        wUserData = {}
        wUserData.update({"id": inUser['Fulluser']})
        ###		wUserData.update({ "username" : str( inROW['account']['display_name'] ) })
        wUserData.update({"username": wDisplay_Name})
        wUserData.update({"domain": inUser['Domain']})
        wUserData.update({"status": "-"})
        wUserData.update({"followed": False})
        wUserData.update({"locked": False})
        wUserData.update({"lupdate": ""})
        ## status
        ##   @ フォローチェック予約(まだ未フォロー)
        ##   - フォローチェック済
        ##   D ドメインブロックユーザ
        ##   R リムーブ予約
        ##   X チェックもしくはフォロー失敗
        ##   * リストから消す

        #############################
        # ステータスの設定
        ###鍵の有無
        ##		if wAccount['locked']==True :
        if inROW['account']['locked'] == True:
            wUserData['locked'] = True

        ###更新時間 (mastodon時間)
        wTime = CLS_OSIF.sGetTimeformat(inROW['created_at'])
        if wTime['Result'] == True:
            wUserData['lupdate'] = wTime['TimeDate']

        #############################
        # 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_UserCorr: AddUser: DB Connect test is failed: " +
                wRes['Reason'])
            wOBJ_DB.Close()
            return False

##		#############################
##		# ユーザ存在チェック
##		wQuery = "id = '" + wUserData['id'] + "'"
##		wDBRes = wOBJ_DB.RunExist( inObjTable="TBL_USER_DATA", inWhere=wQuery )
##		wDBRes = wOBJ_DB.GetQueryStat()
##		if wDBRes['Result']!=True :
##			##失敗
##			self.Obj_Parent.OBJ_Mylog.Log( 'a', "CLS_UserCorr: AddUser: Run Query is failed: " + wDBRes['Reason'] + " query=" + wDBRes['Query'] )
##			wOBJ_DB.Close()
##			return False
##
#############################
# ユーザ取得
        wQuery = "select * from TBL_USER_DATA where id = '" + wUserData[
            'id'] + "' ;"
        wDBRes = wOBJ_DB.RunQuery(wQuery)
        wDBRes = wOBJ_DB.GetQueryStat()
        if wDBRes['Result'] != True:
            ##失敗
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_UserCorr: AddUser: Run Query is failed: " +
                wDBRes['Reason'] + " query=" + wDBRes['Query'])
            wOBJ_DB.Close()
            return False

        wFLG_AddUser = False
        #############################
        # クエリの作成
        ###なければ追加
        ##		if wDBRes['Responce']==False :
        if len(wDBRes['Responce']['Data']) == 0:
            ###ステータスがなければ、チェック候補にする
            if wUserData['status'] == "-":
                wUserData['status'] = "@"

            wQuery = "insert into TBL_USER_DATA values (" + \
               "'" + wUserData['id'] + "'," + \
               "'" + wUserData['username'] + "'," + \
               "'" + wUserData['domain']   + "'," + \
               "'" + wUserData['status']   + "'," + \
               str(wUserData['followed']) + "," + \
               str(wUserData['locked'])   + "," + \
               "'" + str(wUserData['lupdate'])  + "' " + \
               ") ;"

            wFLG_AddUser = True

        ###あれば更新
        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行しかないし切る

            ###領域に詰め直す
            ##			wUserData['id']       = wChgList[0]
            ##			wUserData['username'] = wChgList[1]
            ##			wUserData['domain']   = wChgList[2]
            ###			wUserData['status']   = wChgList[3]
            ###			wUserData['followed'] = wChgList[4]
            wUserData['status'] = wChgList[0][3]
            wUserData['followed'] = wChgList[0][4]
            ##			wUserData['locked']   = wChgList[5]
            ##			wUserData['lupdate']  = wChgList[6]

            wQuery = "update TBL_USER_DATA set " + \
              "status = '"   + str(wUserData['status']) + "', " + \
              "locked = '"   + str(wUserData['locked']) + "', " + \
              "lupdate = '"  + str(wUserData['lupdate']) + "' " + \
              "where id = '" + wUserData['id'] + "' ;"

        #############################
        # クエリ実行
        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

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

        #############################
        # 結果を記録
        if wFLG_AddUser == True:
            ##			self.Obj_Parent.OBJ_Mylog.Log( 'c', "CLS_UserCorr: AddUser: ユーザ追加: " + inUser['Fulluser'] )
            self.STR_Stat['UserAdd'] += 1
        else:
            ##			self.Obj_Parent.OBJ_Mylog.Log( 'c', "CLS_UserCorr: AddUser: ユーザ更新: " + inUser['Fulluser'] )
            self.STR_Stat['UserUpdate'] += 1

        return True
Пример #4
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