Esempio n. 1
0
    def Get_Anap(self):
        #############################
        # 読み出し先初期化
        self.ARR_AnapTL = {}
        wAnapList = []  #解析パターンファイル

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_STR_FILE['PatternPTLFile']
        if CLS_File.sReadFile(wFile_path, outLine=wAnapList) != True:
            return False  #失敗

        #############################
        # データ枠の作成
        wIndex = 0
        for wLine in wAnapList:
            wLine = wLine.split(gVal.DEF_DATA_BOUNDARY)
            if len(wLine) == 2:
                wLine.append("")  #ダミー
            if len(wLine) != 3:
                continue  #フォーマットになってない
            if wLine[0].find("#") == 0:
                continue  #コメントアウト

            self.ARR_AnapTL.update({wIndex: ""})
            self.ARR_AnapTL[wIndex] = {}
            self.ARR_AnapTL[wIndex].update({"Kind": wLine[0]})
            self.ARR_AnapTL[wIndex].update({"Pattern": wLine[1]})
            self.ARR_AnapTL[wIndex].update({"File": wLine[2]})
            wIndex += 1

        ###なしでもOKとする
        return True  #成功
Esempio n. 2
0
    def __getTrendPatt(self):
        #############################
        # 読み出し先初期化
        self.ARR_SendDomain = []
        wSendDomain = []  #解析パターンファイル

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_STR_FILE['TrendTootFile']
        if CLS_File.sReadFile(wFile_path, outLine=wSendDomain) != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_Trend: __getTrendPatt: TrendTootFile read failed: " +
                wFile_path)
            return False  #失敗

        #############################
        # パターンの詰め込み
        for wLine in wSendDomain:
            wLine = wLine.split(gVal.DEF_DATA_BOUNDARY)
            if len(wLine) != 2:
                continue  #フォーマットになってない
            if wLine[0].find("#") == 0:
                continue  #コメントアウト

            #############################
            # ドメイン
            if wLine[0] == "d":
                self.ARR_SendDomain.append(wLine[1])

        return True
Esempio n. 3
0
    def __openLock(cls, inPath):
        wLock = []
        wFilePath = inPath + gVal.DEF_STR_FILE['LockFile']
        if CLS_File.sReadFile(wFilePath, wLock) != True:
            return "3"  #失敗=排他あり にしてる

        return wLock[0]
Esempio n. 4
0
    def sCheckTrafficUser(cls, inUsername):
        #############################
        # 名前の妥当性チェック
        wResUser = cls.sUserCheck(inUsername)
        ##	"Result"	: False,
        ##	"User"		: "",
        ##	"Domain"	: "",
        ##	"Reason"	: "",
        ##	"Registed"	: False,
        if wResUser['Result'] != True:
            return False  #不正

        #############################
        # 読み出し先初期化
        wTrafficUser = []

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_STR_FILE['TrafficFile']
        if CLS_File.sReadFile(wFile_path, outLine=wTrafficUser) != True:
            return False  #失敗

        #############################
        # 対象ユーザか
        if inUsername in wTrafficUser:
            return True  #対象外

        return False  #対象ではない
Esempio n. 5
0
    def sChk1HourTime(cls, inPath):
        #############################
        # 記録ファイルをロード
        w1HourTime = []
        wFilePath = inPath + gVal.DEF_STR_FILE['Chk1HourFile']
        if CLS_File.sReadFile(wFilePath, w1HourTime) != True:
            return False  #処理失敗

        try:
            w1HourTime = w1HourTime[0].split(',')
            wHour = w1HourTime[1]
        except:
            return False  #処理失敗

        #############################
        # PC時間を取得
        wGetTime = CLS_OSIF.sGetTime()
        if wGetTime['Result'] != True:
            return False  #処理失敗

        gVal.STR_TimeInfo['Object'] = wGetTime['Object']
        gVal.STR_TimeInfo['TimeDate'] = wGetTime['TimeDate']
        gVal.STR_TimeInfo['Hour'] = wGetTime['Hour']
        gVal.STR_TimeInfo['Week'] = wGetTime['Week']
        gVal.STR_TimeInfo['Result'] = True  #有効

        wGetDate = wGetTime['TimeDate'].split(" ")

        #############################
        # 時間が同じ=少なくとも1時間経ってないか?
        if w1HourTime[0] != "1900-01-01":
            if wHour == wGetTime['Hour']:
                gVal.STR_TimeInfo['OneHour'] = False
                return True
            else:
                gVal.STR_TimeInfo['OneHour'] = True

            if w1HourTime[0] == wGetDate[0]:
                gVal.STR_TimeInfo['OneDay'] = False
##				return True
            else:
                gVal.STR_TimeInfo['OneDay'] = True

        else:
            ##bot起動初回の場合は時間だけ保存する
            gVal.STR_TimeInfo['OneHour'] = False
            gVal.STR_TimeInfo['OneDay'] = False

        #############################
        # 時間をセーブ
        wTime = wGetTime['TimeDate'].split(" ")
        wTime = wTime[0] + ',' + wGetTime['Hour'] + ',' + wGetTime['Week']

        wSaveTime = []
        wSaveTime.append(wTime)
        if CLS_File.sWriteFile(wFilePath, wSaveTime) != True:
            return False  #処理失敗

        return True
Esempio n. 6
0
    def __recovery_TBL_TRAFFIC_DATA(self):
        #############################
        # 読み出し先初期化
        wTrafficUser = []

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_STR_FILE['TrafficFile']
        if CLS_File.sReadFile(wFile_path, outLine=wTrafficUser) != True:
            wStr = "CLS_Regist : __recovery_TBL_TRAFFIC_DATA: TrafficFile read is failed: " + gVal.DEF_STR_FILE[
                'TrafficFile']
            CLS_OSIF.sPrn(wStr)
            return False

        #############################
        # DBの接続
        wOBJ_DB = CLS_PostgreSQL_Use(gVal.DEF_STR_FILE['DBinfo_File'])
        wRes = wOBJ_DB.GetIniStatus()
        if wRes['Result'] != True:
            ###失敗
            wStr = "CLS_Regist : __recovery_TBL_TRAFFIC_DATA: DB connect error: " + wRes[
                'Reason']
            CLS_OSIF.sPrn(wStr)
            return False

        #############################
        # 修復
        for wLine in wTrafficUser:
            wDomain = wLine.split("@")
            if len(wDomain) != 2:
                wStr = "CLS_Regist : __recovery_TBL_TRAFFIC_DATA: Traffic user is invalid: user="******"insert into TBL_TRAFFIC_DATA values (" + \
               "'" + wDomain + "'," + \
               "0," + \
               "-1," + \
               "-1," + \
               "-1," + \
               "0" + \
               ") ;"
            wDBRes = wOBJ_DB.RunQuery(wQuery)
            wDBRes = wOBJ_DB.GetQueryStat()
            if wDBRes['Result'] != True:
                ##失敗
                wStr = "CLS_Regist : __recovery_TBL_TRAFFIC_DATA: DB insert is failed: " + wDBRes[
                    'Reason']
                CLS_OSIF.sPrn(wStr)
                wOBJ_DB.Close()
                return False

        #############################
        # DBのクローズ
        wOBJ_DB.Close()
        return True
Esempio n. 7
0
    def sChangeTrafficUser(cls, inUsername):
        #############################
        # 名前の妥当性チェック
        wResUser = cls.sUserCheck(inUsername)
        ##	"Result"	: False,
        ##	"User"		: "",
        ##	"Domain"	: "",
        ##	"Reason"	: "",
        ##	"Registed"	: False,
        if wResUser['Result'] != True:
            return False  #不正

        #############################
        # 読み出し先初期化
        wTrafficUser = []

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_STR_FILE['TrafficFile']
        if CLS_File.sReadFile(wFile_path, outLine=wTrafficUser) != True:
            return False  #失敗

        #############################
        # 計測ユーザか
        if inUsername not in wTrafficUser:
            return True  #対象外

        ##自分は抜いておく
        wTrafficUser.remove(inUsername)

        #############################
        # 同一ドメインの別ユーザを検索
        wUserList = cls.sGetUserList()
        wNewUser = None
        for wLine in wUserList:
            if wLine == inUsername:
                continue  #自分は除く

            wDomain = wLine.split("@")
            if wDomain[1] == wResUser['Domain']:
                wNewUser = wLine
                break

        if wNewUser == None:
            ##ありえない
            return False

        #############################
        # 切替
        wTrafficUser.append(wNewUser)

        #############################
        # ファイル書き込み (改行つき)
        wFile_path = gVal.DEF_STR_FILE['TrafficFile']
        if CLS_File.sWriteFile(wFile_path, wTrafficUser, inRT=True) != True:
            return False  #失敗

        return True  #正常
Esempio n. 8
0
    def __getTwitterPatt(self):
        #############################
        # 読み出し先初期化
        self.ARR_AnapTL = {}
        wARR_TwitterReader = []  #解析パターンファイル

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_STR_FILE['TwetterReaderFile']
        if CLS_File.sReadFile(wFile_path, outLine=wARR_TwitterReader) != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_TwitterReader: __getTwitterPatt: TwetterReaderFile read failed: "
                + wFile_path)
            return False  #失敗

        #############################
        # パターンの詰め込み
        wIndex = 0
        for wLine in wARR_TwitterReader:
            wLine = wLine.split(gVal.DEF_DATA_BOUNDARY)
            if len(wLine) == 2:
                ##				#############################
                ##				# 範囲
                ##				if wLine[0]=="r" :
                ##					if wLine[1] in self.DEF_SENDRANGE :
                ##						self.CHR_SendRange = wLine[1]
                ##
                ##				elif wLine[0]=="T" and self.CHR_TrendSender=="" :
                #############################
                # トレンド送信ユーザ
                if wLine[0] == "T" and self.CHR_TrendSender == "":
                    self.CHR_TrendSender = wLine[1]

                continue

##			if len(wLine)!=4 :
            if len(wLine) != 5:
                continue  #フォーマットになってない
            if wLine[0].find("#") == 0:
                continue  #コメントアウト

            #############################
            # アカウント
            if wLine[0] == "P":
                self.ARR_AnapTL.update({wIndex: ""})
                self.ARR_AnapTL[wIndex] = {}
                self.ARR_AnapTL[wIndex].update({"user": wLine[1]})
                self.ARR_AnapTL[wIndex].update({"patt": wLine[2]})
                self.ARR_AnapTL[wIndex].update({"send": wLine[3]})
                self.ARR_AnapTL[wIndex].update({"tags": wLine[4]})
                wIndex += 1

        return True
Esempio n. 9
0
    def Get_RateTwitterTL(self):
        #############################
        # 読み出し先初期化
        self.ARR_RateTL = []

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_MASTERCONFIG + gVal.DEF_STR_FILE['TweetFile']
        if CLS_File.sReadFile(wFile_path, outLine=self.ARR_RateTL) != True:
            return False  #失敗

        return True  #成功
Esempio n. 10
0
    def __get_Rip(self, inFilename):
        #############################
        # 読み出し先初期化
        wARR_Load = []

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_STR_FILE['Toot_path'] + inFilename
        if CLS_File.sReadFile(wFile_path, outLine=wARR_Load) != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_LookPTL: __get_Rip: File read is failure: " + wFile_path)
            return []
        if len(wARR_Load) == 0:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_LookPTL: __get_Rip: The file is empty: " + wFile_path)
            return []

        #############################
        # 候補一覧を取得する
        wARR_RipKouho = []
        for wLine in wARR_Load:
            ###文字がない行
            if len(wLine) == 0:
                continue
            ###コメントアウト
            if wLine.find("#") == 0:
                continue
            ###フォーマット
            wLine = wLine.split(gVal.DEF_DATA_BOUNDARY)
            if len(wLine) != 2:
                continue
            wARR_RipKouho.append(wLine)

        if len(wARR_RipKouho) == 0:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_LookPTL: __get_Rip: Riply kouho is zero")
            return []

        #############################
        # 乱数の取得
        wRand = CLS_OSIF.sGetRand(len(wARR_RipKouho))
        if wRand < 0:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_LookPTL: __get_Rip: sGetRand error: " + str(wRand))
            return []

        #############################
        # リプを出力
        wLine = wARR_RipKouho[wRand]
        return wLine
Esempio n. 11
0
    def Get_RateLTL(self):
        #############################
        # 読み出し先初期化
        self.ARR_RateTL = []

        #############################
        # ファイル読み込み
        wFile_path = self.Obj_Parent.CHR_User_path + gVal.DEF_STR_FILE[
            'Rate_LTLFile']
        if CLS_File.sReadFile(wFile_path, outLine=self.ARR_RateTL) != True:
            return False  #失敗

        return True  #成功
Esempio n. 12
0
    def GetWordREM(self):
        #############################
        # 初期化
        gVal.STR_WordREM = []

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_STR_FILE['WordREMFile']
        if CLS_File.sReadFile(wFile_path, outLine=gVal.STR_WordREM) != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_WordCorr: GetWordREM: WordREM file read failed: " +
                wFile_path)
            return False  #失敗

        return True  #成功
Esempio n. 13
0
    def Get_Anap(self):
        #############################
        # 読み出し先初期化
        self.ARR_AnapTL = {}
        self.ARR_NoBoost = []
        wAnapList = []  #解析パターンファイル

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_STR_FILE['HTLBoostFile']
        if CLS_File.sReadFile(wFile_path, outLine=wAnapList) != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_LookHTL: Get_Anap: HTLBoostFile read failed: " +
                wFile_path)
            return False  #失敗

        #############################
        # データ枠の作成
        wIndex = 0
        for wLine in wAnapList:
            wLine = wLine.split(gVal.DEF_DATA_BOUNDARY)
            if len(wLine) == 3:
                #旧フォーマット
                wLine.append("")
            if len(wLine) != 4:
                continue  #フォーマットになってない
            if wLine[0].find("#") == 0:
                continue  #コメントアウト

            if wLine[0] == "n":  #ブースト外
                self.ARR_NoBoost.append(wLine[1])
                continue

            self.ARR_AnapTL.update({wIndex: ""})
            self.ARR_AnapTL[wIndex] = {}
            self.ARR_AnapTL[wIndex].update({"Kind": wLine[0]})
            self.ARR_AnapTL[wIndex].update({"Tag": wLine[1]})
            self.ARR_AnapTL[wIndex].update({"Fulluser": wLine[2]})
            self.ARR_AnapTL[wIndex].update({"TwitterTags": wLine[3]})
            wIndex += 1

        if len(self.ARR_AnapTL) == 0:
            self.Obj_Parent.OBJ_Mylog.Log(
                'c', "CLS_LookHTL: Get_Anap: HTLBoostFile in none pattern: " +
                wFile_path)
            return False  #パターンなし

        return True
Esempio n. 14
0
    def __getDomainsFile(self):
        #############################
        # 読み出し先初期化
        self.ARR_Domains = []

        #############################
        # ファイル読み込み
        ##		wFile_path = gVal.DEF_STR_FILE['MstdnDomains_File']
        wFile_path = gVal.DEF_STR_FILE[
            'MasterConfig_path'] + gVal.DEF_STR_FILE['MstdnDomains_File']
        if CLS_File.sReadFile(wFile_path, outLine=self.ARR_Domains) != True:
            ##			wStr = "CLS_DBedit: __getDomainsFile: MstdnDomains_File read is failed: " + gVal.DEF_STR_FILE['MstdnDomains_File']
            wStr = "CLS_DBedit: __getDomainsFile: MstdnDomains_File read is failed: " + wFile_path
            CLS_OSIF.sPrn(wStr)
            return False  #失敗

        return True  #成功
Esempio n. 15
0
    def __getTrafficPatt(self):
        #############################
        # 読み出し先初期化
        self.CHR_SendRange = self.DEF_SENDRANGE
        self.ARR_SendDomain = []
        wSendDomain = []  #解析パターンファイル
        ##		wFLG_Range  = False

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_STR_FILE['TrafficTootFile']
        if CLS_File.sReadFile(wFile_path, outLine=wSendDomain) != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_Traffic: __getTrafficPatt: TrafficTootFile read failed: "
                + wFile_path)
            return False  #失敗

        #############################
        # パターンの詰め込み
        for wLine in wSendDomain:
            wLine = wLine.split(gVal.DEF_DATA_BOUNDARY)
            if len(wLine) != 2:
                continue  #フォーマットになってない
            if wLine[0].find("#") == 0:
                continue  #コメントアウト

            #############################
            # 公開範囲
            if wLine[0] == "r":
                if CLS_UserData.sCheckRange(wLine[1]) == True:
                    self.CHR_SendRange = wLine[1]
                    wFLG_Range = True
                    continue

            #############################
            # ドメイン
            if wLine[0] == "d":
                self.ARR_SendDomain.append(wLine[1])

##		if wFLG_Range==False :
##			###デフォルトだと指定あるのでいちお入れる
##			self.Obj_Parent.OBJ_Mylog.Log( 'c', "__getTrafficPatt: トラヒック送信の公開範囲なし(内部設定=" + self.DEF_SENDRANGE + ")" )

        return True
Esempio n. 16
0
    def sGetTrafficUser(cls):
        #############################
        # 応答形式の取得
        #   "Result" : False, "Reason" : None, "Responce" : None
        wRes = CLS_OSIF.sGet_Resp()

        #############################
        # 読み出し先初期化
        wTrafficUser = []

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_STR_FILE['TrafficFile']
        if CLS_File.sReadFile(wFile_path, outLine=wTrafficUser) != True:
            return wRes  #失敗

        wRes['Responce'] = wTrafficUser
        wRes['Result'] = True
        return wRes  #OK
Esempio n. 17
0
    def Get_CLData(self):
        #############################
        # 読み出し先初期化
        self.ARR_CLData = {}
        wCLTootList = []  #トゥートパターン
        wCLDataList = []  #データ

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_STR_FILE['CLTootFile']
        if CLS_File.sReadFile(wFile_path, outLine=wCLTootList) != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_CircleToot: Get_CLData: CLTootFile read failed: " +
                wFile_path)
            return False  #失敗

##		wFile_path = self.Obj_Parent.CHR_User_path + gVal.DEF_STR_FILE['CLDataFile']
        wFile_path = gVal.DEF_STR_FILE[
            'MasterConfig_path'] + gVal.DEF_STR_FILE['CLDataFile']
        if CLS_File.sReadFile(wFile_path, outLine=wCLDataList) != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_CircleToot: Get_CLData: CLDataFile read failed: " +
                wFile_path)
            return False  #失敗

        #############################
        # データ枠の作成
        for wLine in wCLTootList:
            wLine = wLine.split(gVal.DEF_DATA_BOUNDARY)
            if len(wLine) != 3:
                continue  #フォーマットになってない
            if wLine[0].find("#") == 0:
                continue  #コメントアウト

            wIndex = wLine[1] + ":" + wLine[2]
            wKeylist = list(self.ARR_CLData.keys())
            if wIndex in wKeylist:
                continue  #キー被り

            wLine[1] = wLine[1].split(":")
            if len(wLine[1]) != 2:
                continue  #フォーマットになってない

            self.ARR_CLData.update({wIndex: ""})
            self.ARR_CLData[wIndex] = {}
            self.ARR_CLData[wIndex].update({"Valid": True})
            self.ARR_CLData[wIndex].update({"Kind": wLine[0]})
            self.ARR_CLData[wIndex].update({"Sended": "-"})
            self.ARR_CLData[wIndex].update({"Hour": wLine[1][0]})
            self.ARR_CLData[wIndex].update({"Minute": wLine[1][1]})
            self.ARR_CLData[wIndex].update({"TootFile": wLine[2]})

        #############################
        # データの反映
        wKeylist = list(self.ARR_CLData.keys())
        for wKey in wKeylist:
            for wLine in wCLDataList:
                wLine = wLine.split(",")
                if len(wLine) != 5:
                    continue  #フォーマットになってない

                wIndex = wLine[1] + ":" + wLine[2] + ":" + wLine[3]
                if wIndex not in wKeylist:
                    continue  #キーなし

                self.ARR_CLData[wIndex]["Kind"] = wLine[0]
                self.ARR_CLData[wIndex]["Sended"] = wLine[1]
                self.ARR_CLData[wIndex]["Hour"] = wLine[2]
                self.ARR_CLData[wIndex]["Minute"] = wLine[3]
                self.ARR_CLData[wIndex]["TootFile"] = wLine[4]
                self.ARR_CLData[wIndex]["Valid"] = True

        return True  #成功
Esempio n. 18
0
    def sCheckHardUser(cls, inUsername):
        #############################
        # ハード監視対象ユーザ
        #   ・トラヒック監視ユーザの1番目か
        #   ・1番目がMasuerUserの場合は2番目か

        #############################
        # 名前の妥当性チェック
        wResUser = cls.sUserCheck(inUsername)
        ##	"Result"	: False,
        ##	"User"		: "",
        ##	"Domain"	: "",
        ##	"Reason"	: "",
        ##	"Registed"	: False,
        if wResUser['Result'] != True:
            return False  #不正

        #############################
        # 読み出し先初期化
        wTrafficUser = []

        #############################
        # ファイル読み込み
        wFile_path = gVal.DEF_STR_FILE['TrafficFile']
        if CLS_File.sReadFile(wFile_path, outLine=wTrafficUser) != True:
            return False  #失敗

        #############################
        # 何番目かをIndexで取得する
        wI = 0
        wIndex = -1
        for wUser in wTrafficUser:
            if inUsername == wUser:
                wIndex = wI
                break
            wI += 1
##		if wIndex==-1 :
##			return False	#トラヒックユーザではない
##
##		#############################
##		# 1番目でSubUserの場合は確定
##		if wIndex==0 :
##			if gVal.STR_MasterConfig['MasterUser']!=wTrafficUser[0] :
##				return True	#確定
##
##		#############################
##		# 2番目であれば確定
##		#   *この時点で1番目はMasterUserなので
##		if wIndex==1 :
##			return True	#確定
##
#############################
# トラヒックユーザの登録がある場合
        if len(wTrafficUser) > 0:
            if wIndex == -1:
                return False  #トラヒックユーザではない

            #############################
            # 1番目がSubUser かつ対象の場合 =確定
            if gVal.STR_MasterConfig['MasterUser']!=wTrafficUser[0] and \
               wTrafficUser[0] == inUsername :
                return True  #確定

            #############################
            # 1番目がMasterUser かつ自分が2番目だった場合 =確定
            elif gVal.STR_MasterConfig['MasterUser']==wTrafficUser[0] and \
                 wTrafficUser[1] == inUsername :
                return True  #確定

        #############################
        # その他で自分がMasterUserだった場合 =確定
        else:
            if gVal.STR_MasterConfig['MasterUser'] == inUsername:
                return True  #確定

        return False  #対象ではない
Esempio n. 19
0
    def Get_FollowLists(self):
        #############################
        # 読み出し先初期化
        ##		self.ARR_FollowTL = []
        ##		self.ARR_FollowerTL = []
        self.ARR_FollowTL = {}
        self.ARR_FollowerTL = {}
        self.FLG_Update = False

        wARR_GetFile = []
        #############################
        # フォローファイル読み込み
        wFile_path = self.Obj_Parent.CHR_User_path + gVal.DEF_STR_FILE[
            'FollowListFile']
        ##		if CLS_File.sReadFile( wFile_path, outLine=self.ARR_FollowTL )!=True :
        if CLS_File.sReadFile(wFile_path, outLine=wARR_GetFile) != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_Follow: Get_FollowLists: Get follow list file is failed: "
                + wFile_path)
            return False  #失敗
        ###詰め込む
        for wLine in wARR_GetFile:
            if len(wLine) == 0:
                continue
            wLine = wLine.split(gVal.DEF_DATA_BOUNDARY)
            if len(wLine) != 2:
                continue
            self.ARR_FollowTL.update({wLine[1]: wLine[0]})

        wARR_GetFile = []
        #############################
        # フォロワーファイル読み込み
        wFile_path = self.Obj_Parent.CHR_User_path + gVal.DEF_STR_FILE[
            'FollowerListFile']
        ##		if CLS_File.sReadFile( wFile_path, outLine=self.ARR_FollowerTL )!=True :
        if CLS_File.sReadFile(wFile_path, outLine=wARR_GetFile) != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_Follow: Get_FollowLists: Get follower list file is failed: "
                + wFile_path)
            return False  #失敗
        ###詰め込む
        for wLine in wARR_GetFile:
            if len(wLine) == 0:
                continue
            wLine = wLine.split(gVal.DEF_DATA_BOUNDARY)
            if len(wLine) != 2:
                continue
            self.ARR_FollowerTL.update({wLine[1]: wLine[0]})

        #############################
        # 自動リムーブ
        self.__autoRemove()

        #############################
        # bot起動の最初か、1時間経っていればmastodonから取得する
        #  *** フォロー・フォロワーがいないと常に取りにいってしまう
        wARR_FollowList = list(self.ARR_FollowTL)
        wARR_FollowerList = list(self.ARR_FollowerTL)
        ##		if len(self.ARR_FollowTL)>0 or len(self.ARR_FollowerTL)>0 :
        ##			if gVal.STR_TimeInfo['OneDay']==False :
        if len(wARR_FollowList) > 0 or len(wARR_FollowerList) > 0:
            if gVal.STR_TimeInfo['OneHour'] == False:
                return True  #正常で返す

        #############################
        # mastodonから取得しなおす
        #############################
        # 自アカウントのフォロー一覧を取得
        wRes = self.__get_FollowTL(self.Obj_Parent.ARR_MyAccountInfo['id'])
        if wRes['Result'] != True:
            ##失敗
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_Follow: Get_FollowLists: Get follow list is failed: " +
                wRes['Reason'])
            return False

        #############################
        # 自アカウントのフォロワー一覧を取得
        wRes = self.__get_FollowerTL(self.Obj_Parent.ARR_MyAccountInfo['id'])
        if wRes['Result'] != True:
            ##失敗
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_Follow: Get_FollowLists: Get follower list is failed: " +
                wRes['Reason'])
            return False

        self.FLG_Update = True
        return True
Esempio n. 20
0
	def __delTrafficUser( self, inUsername ):
		#############################
		# 応答データ
		wRes = {
			"Result"	: False,
			"Reason"	: "",
			"Update"	: False
		}
		
		#############################
		# 名前の妥当性チェック
		wResUser = CLS_UserData.sUserCheck( inUsername )
			##	"Result"	: False,
			##	"User"		: "",
			##	"Domain"	: "",
			##	"Reason"	: "",
			##	"Registed"	: False,
##		if wResUser['Result']!=True or wResUser['Registed']==False :
		if wResUser['Result']!=True :
			wRes['Reason'] = "CLS_Regist : __delTrafficUser: Username is not valid: " + inUsername
			return wRes	#不正
		
		#############################
		# 読み出し先初期化
		wTrafficUser = []
		
		#############################
		# ファイル読み込み
		wFile_path = gVal.DEF_STR_FILE['TrafficFile']
		if CLS_File.sReadFile( wFile_path, outLine=wTrafficUser )!=True :
			wRes['Reason'] = "CLS_Regist : __delTrafficUser: TrafficFile read is failed: " + gVal.DEF_STR_FILE['TrafficFile']
			return wRes	#失敗
		
		#############################
		# トラヒック対象ではなら削除しない
		if inUsername not in wTrafficUser :
			wRes['Result'] = True
			return wRes	#削除しないで終了
		
		###対象なので削除する
		wTrafficUser.remove( inUsername )
		
		#############################
		# ユーザ一覧取得
		wUserList = CLS_UserData.sGetUserList()
		
		#############################
		# 削除ユーザと同一の既登録ドメインがあるか
		wUsername = None
		for wLine in wUserList :
			wDomain = wLine.split("@")
			if wDomain[1]==wResUser['Domain'] :
				## 既登録で既にドメインがあった
				wUsername = wLine
				break
		
		if wUsername!=None :
			##同一ドメインの別ユーザに切り替える
			wTrafficUser.append( wUsername )
		else :
			##同一ドメインの別ユーザがなければDBから削除する
			#############################
			# DB接続
			wOBJ_DB = CLS_PostgreSQL_Use( gVal.DEF_STR_FILE['DBinfo_File'] )
			wDBRes = wOBJ_DB.GetIniStatus()
			if wDBRes['Result']!=True :
				##失敗
				wRes['Reason'] = "CLS_Regist : __delTrafficUser: DB Connect test is failed: " + wDBRes['Reason']
##				wOBJ_DB.Close()
				return wRes
			
			#############################
			# ドメイン存在チェック
			wQuery = "domain = '" + wResUser['Domain'] + "'"
			wDBRes = wOBJ_DB.RunExist( inObjTable="TBL_TRAFFIC_DATA", inWhere=wQuery )
			wDBRes = wOBJ_DB.GetQueryStat()
			if wDBRes['Result']!=True :
				##失敗
##				wRes['Reason'] = "CLS_Regist : __delTrafficUser: Run Query is failed: " + wDBRes['Reason']
				wRes['Reason'] = "CLS_Regist : __delTrafficUser: Run Query is failed: " + wDBRes['Reason'] + " query=" + wDBRes['Query']
				wOBJ_DB.Close()
				return wRes
			
			#############################
			# 存在していれば削除
			if wDBRes['Responce']==True :
				wQuery = "delete from TBL_TRAFFIC_DATA where domain = '" + wResUser['Domain'] + \
							"' ;"
				wDBRes = wOBJ_DB.RunQuery( wQuery )
				wDBRes = wOBJ_DB.GetQueryStat()
				if wDBRes['Result']!=True :
					##失敗
					wRes['Reason'] = "CLS_Regist : __delTrafficUser: DB insert is failed: " + wDBRes['Reason']
					wOBJ_DB.Close()
					return wRes
			
			#############################
			# DB切断
			wRes['Update'] = True	#DBからは削除
			wOBJ_DB.Close()
		
		#############################
		# トラヒックを更新
		if self.__setTrafficUser( wTrafficUser )!=True :
			wRes['Reason'] = "CLS_Regist : __delTrafficUser: TrafficFile write is failed: " + gVal.DEF_STR_FILE['TrafficFile']
			return wRes
		
		#############################
		# 正常
		wRes['Result'] = True
		return wRes
Esempio n. 21
0
	def __regTrafficUser( self, inUsername ):
		#############################
		# 応答データ
		wRes = {
			"Result"	: False,
			"Reason"	: "",
			"Update"	: False
		}
		
		#############################
		# 名前の妥当性チェック
		wResUser = CLS_UserData.sUserCheck( inUsername )
			##	"Result"	: False,
			##	"User"		: "",
			##	"Domain"	: "",
			##	"Reason"	: "",
			##	"Registed"	: False,
		if wResUser['Result']!=True or wResUser['Registed']==False :
			wRes['Reason'] = "CLS_Regist : __regTrafficUser: Username is not valid: " + inUsername
			return wRes	#不正
		
		#############################
		# 読み出し先初期化
		wTrafficUser = []
		
		#############################
		# ファイル読み込み
		wFile_path = gVal.DEF_STR_FILE['TrafficFile']
		if CLS_File.sReadFile( wFile_path, outLine=wTrafficUser )!=True :
			wRes['Reason'] = "CLS_Regist : __regTrafficUser: TrafficFile read is failed: " + gVal.DEF_STR_FILE['TrafficFile']
			return wRes	#失敗
		
		#############################
		# 既登録のドメインがあるか
		wFlg = False
		for wLine in wTrafficUser :
			wDomain = wLine.split("@")
			if wDomain[1]==wResUser['Domain'] :
				## 既登録で既にドメインがあった
				if wLine==gVal.STR_MasterConfig['MasterUser'] :
					##MasterUserの場合差し替え
					wTrafficUser.remove( gVal.STR_MasterConfig['MasterUser'] )
				else :
					##登録あり
					wFlg = True
				break
		
		if wFlg==True :
			wRes['Result'] = True
			return wRes	#更新しないで終了
		
		#############################
		# DBに登録
		
		#############################
		# DB接続
		wOBJ_DB = CLS_PostgreSQL_Use( gVal.DEF_STR_FILE['DBinfo_File'] )
		wDBRes = wOBJ_DB.GetIniStatus()
		if wDBRes['Result']!=True :
			##失敗
			wRes['Reason'] = "CLS_Regist : __regTrafficUser: DB Connect test is failed: " + wDBRes['Reason']
##			wOBJ_DB.Close()
			return wRes
		
		#############################
		# ドメイン存在チェック
		wQuery = "domain = '" + wResUser['Domain'] + "'"
		wDBRes = wOBJ_DB.RunExist( inObjTable="TBL_TRAFFIC_DATA", inWhere=wQuery )
		wDBRes = wOBJ_DB.GetQueryStat()
		if wDBRes['Result']!=True :
			##失敗
##			wRes['Reason'] = "CLS_Regist : __regTrafficUser: Run Query is failed: " + wDBRes['Reason']
			wRes['Reason'] = "CLS_Regist : __regTrafficUser: Run Query is failed: " + wDBRes['Reason'] + " query=" + wDBRes['Query']
			wOBJ_DB.Close()
			return wRes
		
		#############################
		# 存在しなければ追加
		if wDBRes['Responce']==False :
			wQuery = "insert into TBL_TRAFFIC_DATA values (" + \
						"'" + wResUser['Domain'] + "'," + \
						"0," + \
						"-1," + \
						"-1" + \
						") ;"
			wDBRes = wOBJ_DB.RunQuery( wQuery )
			wDBRes = wOBJ_DB.GetQueryStat()
			if wDBRes['Result']!=True :
				##失敗
				wRes['Reason'] = "CLS_Regist : __regTrafficUser: DB insert is failed: " + wDBRes['Reason']
				wOBJ_DB.Close()
				return wRes
		
		#############################
		# DB切断
		wOBJ_DB.Close()
		
		#############################
		# トラヒックに登録
		wTrafficUser.append( inUsername )
		if self.__setTrafficUser( wTrafficUser )!=True :
			wRes['Reason'] = "CLS_Regist : __regTrafficUser: TrafficFile write is failed: " + gVal.DEF_STR_FILE['TrafficFile']
			return wRes
		
		#############################
		# 正常
		wRes['Update'] = True
		wRes['Result'] = True
		return wRes
Esempio n. 22
0
    def __sendToot(self, inKind, inFileName):
        #############################
        # 応答形式の取得
        #   "Result" : False, "Reason" : None, "Responce" : None
        wRes = CLS_OSIF.sGet_Resp()

        #############################
        # ファイル読み出し
        wToot = []

        wFile_path = gVal.DEF_STR_FILE['Toot_path'] + inFileName
        if CLS_File.sReadFile(wFile_path, outLine=wToot) != True:
            wRes[
                'Reason'] = "CLS_CircleToot: __sendToot: Toot file read failed: " + wFile_path
            return wRes  #失敗

        if len(wToot) <= 1:
            wRes[
                'Reason'] = "CLS_CircleToot: __sendToot: Toot is sortest: " + wFile_path
            return wRes  #失敗

        #############################
        # 範囲の設定
        wRange = CLS_UserData.sGetRange(wToot[0])
        del wToot[0]

        #############################
        # 種別=CWトゥート
        if inKind == "w":
            wTitle = self.DEF_TITLE_PRTOOT + " " + wToot[0]
            del wToot[0]
            wSetToot = ""
        else:
            wSetToot = self.DEF_TITLE_PRTOOT + " "

        #############################
        # トゥートの組み立て
        for wLine in wToot:
            wSetToot = wSetToot + wLine + '\n'

##		wSetToot = wSetToot + " " + gVal.STR_MasterConfig['prTag']
##
##		# 管理者がいれば通知する
##		if gVal.STR_MasterConfig['AdminUser']!="" and gVal.STR_MasterConfig['AdminUser']!=self.Obj_Parent.CHR_Account:
##			wSetToot = wSetToot + '\n' + '\n' + "[Admin] @" + gVal.STR_MasterConfig['AdminUser']
##
        wSetToot = wSetToot + '\n' + "#" + gVal.STR_MasterConfig['prTag']

        if len(wSetToot) > 500:
            wRes[
                'Reason'] = "CLS_CircleToot: __sendToot: Create toot is over length"
            return wRes  #失敗

        #############################
        # トゥートの送信
        if inKind == "w":
            wRes = self.Obj_Parent.OBJ_MyDon.Toot(status=wSetToot,
                                                  visibility=wRange,
                                                  spoiler_text=wTitle)
        else:
            wRes = self.Obj_Parent.OBJ_MyDon.Toot(status=wSetToot,
                                                  visibility=wRange)

        if wRes['Result'] != True:
            wRes[
                'Reason'] = "CLS_LookRIP: __copeFavo: Mastodon error: " + wRes[
                    'Reason']
            return wRes

        wRes['Result'] = True
        return wRes