def __checkTwitterPatt(self, inROW): wRes = {"result": False, "send_user": "", "tags": ""} wKeylist = self.ARR_AnapTL.keys() wFlg_Hit = False for wKey in wKeylist: ## if self.ARR_AnapTL[wKey]['user']==str(inROW['user']['screen_name']) : ## wFlg_Hit = True ## break #対象ツイートユーザ if self.ARR_AnapTL[wKey]['user'] != str( inROW['user']['screen_name']): #対象ツイートユーザではない continue if self.ARR_AnapTL[wKey]['patt'] == "": ## continue #対象ツイートユーザ かつ パターン設定なし:Hitあり wFlg_Hit = True break wRes_Search = CLS_OSIF.sRe_Search(self.ARR_AnapTL[wKey]['patt'], str(inROW['text'])) if wRes_Search: #対象ツイートユーザ かつ パターンヒット:Hitあり wFlg_Hit = True break ### Hitあり if wFlg_Hit == True: wRes['send_user'] = self.ARR_AnapTL[wKey]['send'] wRes['tags'] = self.ARR_AnapTL[wKey]['tags'] wRes['result'] = True return wRes
def __cope(self, inROW): ############################# # ユーザ名の変換 wFulluser = CLS_UserData.sGetFulluser(inROW['account']['username'], inROW['account']['url']) if wFulluser['Result'] != True: ###今のところ通らないルート return False ############################# # トゥートからHTMLタグを除去 wCont = CLS_OSIF.sDel_HTML(inROW['content']) ############################# # 収集判定(一括) if self.__copeCorr(wFulluser, inROW, wCont) != True: ## self.STR_Cope['Outrange'] += 1 return ### 除外 ############################# # トゥートの時間 (変換&差) wReaRIPmin = gVal.DEF_STR_TLNUM['reaRIPmin'] * 60 #秒に変換 wGetLag = CLS_OSIF.sTimeLag(str(inROW['created_at']), inThreshold=wReaRIPmin) if wGetLag['Result'] != True: self.STR_Cope['Invalid'] += 1 return if wGetLag['Beyond'] == True: self.STR_Cope['OffTime'] += 1 return #反応時間外 wGetTime = str(wGetLag['InputTime']) ############################# #解析種類の判定 wKeyList = self.ARR_AnapTL.keys() for wKey in wKeyList: ############################# # 解析:ついったー転送 if self.ARR_AnapTL[wKey]['Kind'] == "t" and gVal.STR_MasterConfig[ 'Twitter'] == "on": ### ハード監視ユーザか if CLS_UserData.sCheckHardUser( self.Obj_Parent.CHR_Account) != True: continue ### 自分が指定ユーザか if self.ARR_AnapTL[wKey]['Fulluser'] != "": if self.ARR_AnapTL[wKey][ 'Fulluser'] != self.Obj_Parent.CHR_Account: continue ### 無指定の場合、登録ユーザか(第三者避け) else: wUserList = CLS_UserData.sGetUserList() if wFulluser['Fulluser'] not in wUserList: continue ### マッチチェック wPatt = "#" + self.ARR_AnapTL[wKey]['Tag'] wRes = CLS_OSIF.sRe_Search(wPatt, wCont) if not wRes: ##アンマッチ continue ### 実行 ## if self.TwitterBoost( inROW['id'] )!=True : if self.TwitterBoost(inROW['id'], wFulluser) != True: self.STR_Cope['Invalid'] += 1 else: self.STR_Cope["Now_Twitter"] += 1 ############################# # 解析:指定ブースト if self.ARR_AnapTL[wKey]['Kind'] == "h": ### 自分のトゥートか if wFulluser['Fulluser'] == self.Obj_Parent.CHR_Account: continue #自分 ## ### 収集判定(一括) ## if self.__copeCorr( wFulluser, inROW, wCont )!=True : ## continue # 除外 ### 自分が指定ユーザではない if self.ARR_AnapTL[wKey]['Fulluser'] != "": if self.ARR_AnapTL[wKey][ 'Fulluser'] != self.Obj_Parent.CHR_Account: continue ### 無指定の場合、登録ユーザか(第三者避け) else: wUserList = CLS_UserData.sGetUserList() if wFulluser['Fulluser'] not in wUserList: continue ### マッチチェック wPatt = "#" + self.ARR_AnapTL[wKey]['Tag'] wRes = CLS_OSIF.sRe_Search(wPatt, wCont) if not wRes: ##アンマッチ continue ### 実行 if self.Boost(inROW['id']) != True: self.STR_Cope['Invalid'] += 1 break self.STR_Cope["Now_Boot"] += 1 break ############################# # 解析:指定フルブースト if self.ARR_AnapTL[wKey]['Kind'] == "p": ### 自分のトゥートか if wFulluser['Fulluser'] == self.Obj_Parent.CHR_Account: continue #自分 ## ### 収集判定(一括) ## if self.__copeCorr( wFulluser, inROW, wCont )!=True : ## continue # 除外 ### 自分が指定ユーザではない if self.ARR_AnapTL[wKey][ 'Fulluser'] != self.Obj_Parent.CHR_Account: continue #指定ではない #対象のブーストユーザか if self.ARR_AnapTL[wKey]['Tag'] != wFulluser: continue #指定ではない ### 実行 if self.Boost(inROW['id']) != True: self.STR_Cope['Invalid'] += 1 break self.STR_Cope["Now_Boot"] += 1 break return
def WordStudy(self, inCont): ############################# # 単語なし if inCont == "": return False ############################# # ' 文字が含まれていたら除外する ## wRes = CLS_OSIF.sRe_Search( "'", inCont ) ## if wRes : if inCont.find("'") >= 0: return False ############################# # ワード収集が有効か if gVal.STR_MasterConfig['WordStudy'] != "on": return False #無効 ############################# # 今回の学習数が上限か if self.STR_Stat['StudyNum'] >= gVal.DEF_STR_TLNUM['studyNum']: 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_WordCorr: WordStudy: DB Connect test is failed: " + wRes['Reason']) wOBJ_DB.Close() return False wVAL_Rate_WordNum = -1 ############################# # 1日1回、古いレコードを削除する if gVal.STR_TimeInfo['OneDay'] == True: ###現在のレコード数 wDBRes = wOBJ_DB.RunCount("TBL_WORD_CORRECT") wDBRes = wOBJ_DB.GetQueryStat() if wDBRes['Result'] != True: ##失敗 self.Obj_Parent.OBJ_Mylog.Log( 'a', "CLS_WordCorr: WordStudy: Run Query is failed: " + wDBRes['Reason'] + " query=" + wDBRes['Query']) wOBJ_DB.Close() return False wVAL_Rate_WordNum = wDBRes['Responce'] ###指定日付の抽出 wLag = gVal.DEF_STR_TLNUM['studyDay'] * 24 * 60 * 60 ## wLagTime = CLS_OSIF.sTimeLag( gVal.STR_TimeInfo['TimeDate'], inThreshold=wLag, inTimezone=-1 ) wLagTime = CLS_OSIF.sTimeLag(inThreshold=wLag, inTimezone=-1) if wLagTime['Result'] != True: ##失敗 self.Obj_Parent.OBJ_Mylog.Log( 'a', "CLS_WordCorr: WordStudy: sTimeLag is failed") wOBJ_DB.Close() return False ###単語テーブル wQuery = "delete from TBL_WORD_CORRECT 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_WordCorr: WordStudy: Run Query is failed (Old TBL_WORD_CORRECT delete): " + wDBRes['Reason'] + " query=" + wDBRes['Query']) wOBJ_DB.Close() return False ###品詞パターン テーブル wQuery = "delete from TBL_CLAZ_LIST 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_WordCorr: WordStudy: Run Query is failed (Old TBL_CLAZ_LIST delete): " + wDBRes['Reason'] + " query=" + wDBRes['Query']) wOBJ_DB.Close() return False ###削除後レコード数 wDBRes = wOBJ_DB.RunCount("TBL_WORD_CORRECT") wDBRes = wOBJ_DB.GetQueryStat() if wDBRes['Result'] != True: ##失敗 self.Obj_Parent.OBJ_Mylog.Log( 'a', "CLS_WordCorr: WordStudy: Run Query is failed: " + wDBRes['Reason'] + " query=" + wDBRes['Query']) wOBJ_DB.Close() return False wVAL_WordNum = wDBRes['Responce'] ###削除数 wVAL_Delete_WordNum = wVAL_Rate_WordNum - wVAL_WordNum self.STR_Stat["Delete"] += wVAL_Delete_WordNum self.Obj_Parent.OBJ_Mylog.Log( 'b', "古い単語・品詞パターン削除: 対象=" + str(wLagTime['RateTime']) + " 以前") ############################# # レコード数の抽出 if wVAL_Rate_WordNum == -1: ###削除で結果出してない場合に処理する wDBRes = wOBJ_DB.RunCount("TBL_WORD_CORRECT") wDBRes = wOBJ_DB.GetQueryStat() if wDBRes['Result'] != True: ##失敗 self.Obj_Parent.OBJ_Mylog.Log( 'a', "CLS_WordCorr: WordStudy: Run Query is failed: " + wDBRes['Reason'] + " query=" + wDBRes['Query']) wOBJ_DB.Close() return False wVAL_WordNum = wDBRes['Responce'] ############################# # 学習数が上限か if gVal.DEF_STR_TLNUM['studyMax'] <= wVAL_WordNum: if self.STR_Stat['WordLimit'] == False: self.Obj_Parent.OBJ_Mylog.Log( 'b', "学習不能(単語登録数上限: " + str(gVal.DEF_STR_TLNUM['studyMax']) + "件)") self.STR_Stat['WordLimit'] = True wOBJ_DB.Close() return False #上限 ############################# # デコーダで解読 (出力は辞書型) wGetWords = self.__analizeMeCab(inCont) if len(wGetWords) == 0: self.Obj_Parent.OBJ_Mylog.Log( 'a', "CLS_WordCorr: WordStudy: MeCab analize result is zero, or failed" ) wOBJ_DB.Close() return False #失敗 # ここまでで登録処理確定 ############################# self.STR_Stat['Cope'] += len(wGetWords) #単語数を記録 ## ############################# ## # トゥートから時間を取得 ## wTime = CLS_OSIF.sGetTimeformat( inCreateAt ) ## if wTime['Result']==True : ## wTime = wTime['TimeDate'] ## else: ## wTime = None ## ############################# # 解読した結果(単語)を判定しながら詰めていく wKeylist = wGetWords.keys() #キーはIndex整数 wClazList = "" #文書パターン for wKey in wKeylist: ############################# # 登録済みの単語か wQuery = "word = '" + wGetWords[wKey]['word'] + "'" wDBRes = wOBJ_DB.RunExist("TBL_WORD_CORRECT", wQuery) wDBRes = wOBJ_DB.GetQueryStat() if wDBRes['Result'] != True: ##失敗 self.Obj_Parent.OBJ_Mylog.Log( 'a', "CLS_WordCorr: WordStudy: Run Query is failed (Word check): " + wDBRes['Reason'] + " query=" + wDBRes['Query']) wOBJ_DB.Close() return False if wDBRes['Responce'] == True: ###登録済み ### 触れたので時刻を更新 wQuery = "update TBL_WORD_CORRECT set " + \ "lupdate = '" + str(gVal.STR_TimeInfo['TimeDate']) + "' " + \ "where word = '" + wGetWords[wKey]['word'] + "' ;" wDBRes = wOBJ_DB.RunQuery(wQuery) wDBRes = wOBJ_DB.GetQueryStat() if wDBRes['Result'] != True: ##失敗 self.Obj_Parent.OBJ_Mylog.Log( 'a', "CLS_WordCorr: WordStudy: Run Query is failed (Word check, time update): " + wDBRes['Reason'] + " query=" + wDBRes['Query']) wOBJ_DB.Close() return False ###品詞パターンは記録する wClazList = wClazList + wGetWords[wKey]['claz'] + "," continue #登録済なのでスキップ ############################# # 除外する品詞か #### BOS/EOS if wGetWords[wKey]['claz'] == "BOS/EOS": continue #### 意識不明な単語、パターンとして使えない単語 if (wGetWords[wKey]['claz'] == "名詞" and wGetWords[wKey]['yomi'] == "*" and wGetWords[wKey]['cla1'] == "サ変接続" ) or \ (wGetWords[wKey]['claz'] == "名詞" and wGetWords[wKey]['cla1'] == "数" ) or \ wGetWords[wKey]['claz'] == "記号" : continue #### 名詞かつ 3文字以内の半角英字 if (wGetWords[wKey]['claz'] == "名詞" and wGetWords[wKey]['cla1'] == "一般" ) or \ (wGetWords[wKey]['claz'] == "名詞" and wGetWords[wKey]['cla1'] == "固有名詞" and wGetWords[wKey]['cla2'] == "組織" ) : wRes = CLS_OSIF.sRe_Search(r'^[a-zA-Z]+$', wGetWords[wKey]['word']) if wRes: if len(wGetWords[wKey]['word']) <= 3: continue #### 禁止ワードを含むか ## if self.CheckWordREM( wGetWords[wKey]['word'] )==False : if wGetWords[wKey]['word'] in gVal.STR_WordREM: continue #禁止あり ###**ループ中に辞書の登録上限を超えても何もしない仕様(DBだしええかと) ############################# # 単語の登録 wWord = str(wGetWords[wKey]['word']).replace("'", "''") wClaz = str(wGetWords[wKey]['claz']).replace("'", "''") wYomi = str(wGetWords[wKey]['yomi']).replace("'", "''") wQuery = "insert into TBL_WORD_CORRECT values (" + \ "'" + wWord + "'," + \ "'" + wClaz + "'," + \ "'" + wYomi + "'," + \ "'" + wGetWords[wKey]['cla1'] + "'," + \ "'" + wGetWords[wKey]['cla2'] + "'," + \ "'" + wGetWords[wKey]['cla3'] + "'," + \ "'" + wGetWords[wKey]['ktyp'] + "'," + \ "'" + wGetWords[wKey]['kkat'] + "'," + \ "'" + str(gVal.STR_TimeInfo['TimeDate']) + "'," + \ "False " + \ ") ;" wDBRes = wOBJ_DB.RunQuery(wQuery) wDBRes = wOBJ_DB.GetQueryStat() if wDBRes['Result'] != True: ##失敗 self.Obj_Parent.OBJ_Mylog.Log( 'a', "CLS_WordCorr: WordStudy: Run Query is failed (Word regist): " + wDBRes['Reason'] + " query=" + wDBRes['Query']) wOBJ_DB.Close() return False self.STR_Stat['Regist'] += 1 ###品詞パターンは記録する wClazList = wClazList + wGetWords[wKey]['claz'] + "," ############################# # 今回の学習回数更新 self.STR_Stat['StudyNum'] += 1 ############################# # 品詞パターン学習 if wClazList != "": wClazList = wClazList[0:len(wClazList) - 1] #末尾の','を抜く ###同じ品詞パターンがあるか wQuery = "claz = '" + wClazList + "'" wDBRes = wOBJ_DB.RunExist("TBL_CLAZ_LIST", wQuery) wDBRes = wOBJ_DB.GetQueryStat() if wDBRes['Result'] != True: ##失敗 self.Obj_Parent.OBJ_Mylog.Log( 'a', "CLS_WordCorr: WordStudy: Run Query is failed (Claz check): " + wDBRes['Reason'] + " query=" + wDBRes['Query']) wOBJ_DB.Close() return False if wDBRes['Responce'] == True: ###登録済みならここで終わる(正常) wOBJ_DB.Close() return True ###登録なしなら、登録する ### **ここで品詞パターンの登録上限を超えても何もしない仕様(DBだしええかと) wQuery = "insert into TBL_CLAZ_LIST values (" + \ "'" + wClazList + "'," + \ "'" + str(gVal.STR_TimeInfo['TimeDate']) + "'," + \ "False " + \ ") ;" wDBRes = wOBJ_DB.RunQuery(wQuery) wDBRes = wOBJ_DB.GetQueryStat() if wDBRes['Result'] != True: ##失敗 self.Obj_Parent.OBJ_Mylog.Log( 'a', "CLS_WordCorr: WordStudy: Run Query is failed (Claz regist): " + wDBRes['Reason'] + " query=" + wDBRes['Query']) wOBJ_DB.Close() return False self.STR_Stat['ClazList'] += 1 ############################# # 正常終了 wOBJ_DB.Close() return True
def __cope(self, inROW): ############################# # ユーザ名の変換 wFulluser = CLS_UserData.sGetFulluser(inROW['account']['username'], inROW['account']['url']) if wFulluser['Result'] != True: ###今のところ通らないルート return False ############################# # トゥートからHTMLタグを除去 wCont = CLS_OSIF.sDel_HTML(inROW['content']) ############################# # 収集判定(一括) if self.__copeCorr(wFulluser, inROW['language'], wCont) != True: return ### 除外 ############################# #ユーザ収集ファイルに記録 # ・新規 :追加 # ・追加済:更新 ## if self.Obj_Parent.OBJ_UserCorr.AddUser( inROW )==True : ## self.STR_Cope['UserCorr'] += 1 ## self.Obj_Parent.OBJ_UserCorr.AddUser( inROW ) self.Obj_Parent.OBJ_UserCorr.AddUser(inROW, wFulluser) ############################# #単語学習 ## if gVal.STR_MasterConfig['WordStudy'] == "on" : ## self.Obj_Parent.OBJ_WordCorr.WordStudy( inROW ) ## self.Obj_Parent.OBJ_WordCorr.WordStudy( wCont, inROW['created_at'] ) self.Obj_Parent.OBJ_WordCorr.WordStudy(wCont) ## ############################# ## #パターン反応 ## ###トゥートからHTMLタグを除去 ## wCont = CLS_OSIF.sDel_HTML( inROW['content'] ) ## ## ###ユーザ名の変換 ## wFulluser = CLS_UserData.sGetFulluser( inROW['account']['username'], inROW['account']['url'] ) ## if wFulluser['Result']!=True : ## ###今のところ通らないルート ## return False ## ## ############################# ## #除外トゥート ## ###リプライ(先頭に@付きトゥート) ## if wCont.find('@') == 0 : ## return ## ## ###自分(このbot)のトゥート ## if wFulluser['Fulluser'] == self.Obj_Parent.CHR_Account : ## return ############################# # フォロワー状態 # True =フォロワー # False=フォロワーじゃない wFLG_Follower = self.Obj_Parent.OBJ_Follow.Check_Follower( wFulluser['Fulluser']) ############################# #解析種類の判定 wKeyList = self.ARR_AnapTL.keys() for wKey in wKeyList: ############################# #解析:ニコる if self.ARR_AnapTL[wKey]['Kind']=="f" and gVal.STR_MasterConfig['PTL_Favo']=="on" and \ wFLG_Follower==True : ###マッチチェック wRes = CLS_OSIF.sRe_Search(self.ARR_AnapTL[wKey]['Pattern'], wCont) if not wRes: ##アンマッチ continue ###実行 if self.Nicoru(inROW['id']) != True: break self.STR_Cope["Now_Favo"] += 1 break ############################# #解析:ブースト if self.ARR_AnapTL[wKey]['Kind']=="b" and gVal.STR_MasterConfig['PTL_Boot']=="on" and \ wFLG_Follower==True : ###マッチチェック wRes = CLS_OSIF.sRe_Search(self.ARR_AnapTL[wKey]['Pattern'], wCont) if not wRes: ##アンマッチ continue ###実行 if self.Boost(inROW['id']) != True: break self.STR_Cope["Now_Boot"] += 1 break ############################# #解析:紐エアリプ if self.ARR_AnapTL[wKey]['Kind']=="h" and gVal.STR_MasterConfig['PTL_HRip']=="on" and \ wFLG_Follower==True : ###マッチチェック wRes = CLS_OSIF.sRe_Search(self.ARR_AnapTL[wKey]['Pattern'], wCont) if not wRes: ##アンマッチ continue ###実行 if self.HimoRipry(self.ARR_AnapTL[wKey]['File'], inROW['id']) != True: break self.STR_Cope["Now_ARip"] += 1 break ############################# #解析:エアリプ ## if self.ARR_AnapTL[wKey]['Kind']=="a" and gVal.STR_MasterConfig['PTL_ARip']=="on" and \ ## wFLG_Follower==True : if self.ARR_AnapTL[wKey]['Kind'] == "a" and gVal.STR_MasterConfig[ 'PTL_ARip'] == "on": ###マッチチェック wRes = CLS_OSIF.sRe_Search(self.ARR_AnapTL[wKey]['Pattern'], wCont) if not wRes: ##アンマッチ continue ###実行 if self.AirRipry(self.ARR_AnapTL[wKey]['File']) != True: break self.STR_Cope["Now_ARip"] += 1 break ############################# #解析:ワード監視 if self.ARR_AnapTL[wKey]['Kind']=="w" and gVal.STR_MasterConfig['PTL_WordOpe']=="on" and \ gVal.STR_MasterConfig['AdminUser']!="" : ###マッチチェック wRes = CLS_OSIF.sRe_Search(self.ARR_AnapTL[wKey]['Pattern'], wCont) if not wRes: ##アンマッチ continue ###実行 if self.IndWordOpe(wFulluser['Fulluser'], self.ARR_AnapTL[wKey]['Pattern'], inROW['uri']) != True: break self.STR_Cope["Now_Word"] += 1 break return