예제 #1
0
파일: regist.py 프로젝트: xfyer/lucibot
	def __registUser( self, inFulluser, inMail, inPass ):
		#############################
		# 応答形式の取得
		#   "Result" : False, "Reason" : None, "Responce" : None
		wRes = CLS_OSIF.sGet_Resp()
		
		#############################
		# ユーザ名の妥当性チェック(いちお再チェック)
		wSTR_user = CLS_UserData.sUserCheck( inFulluser )
		if wSTR_user['Result']!=True :
			wRes['Reason'] = wSTR_user['Reason']
			return wRes
		
		#############################
		# 入力間違いのチェック
		wFlg = True
		if inFulluser==inMail :
			wFlg = False
		elif inFulluser==inPass :
			wFlg = False
		elif inMail==inPass :
			wFlg = False
		
		if wFlg!=True :
			wRes['Reason'] = "ユーザ名、メールアドレス、パスワードの入力が誤ってます。(重複検出)"
			return wRes
		
		wRes['Result'] = True
		return wRes
예제 #2
0
    def __get_FollowerTL(self, inMyID):
        ##		self.ARR_FollowerTL = []
        self.ARR_FollowerTL = {}
        wGetList = []
        wNext_Id = None
        wMax_Toots = gVal.DEF_STR_TLNUM["getFollowerTLnum"]
        while (len(wGetList) < wMax_Toots):
            #############################
            # TL取得
            wRes = self.Obj_Parent.OBJ_MyDon.GetFollowersList(id=inMyID,
                                                              limit=40,
                                                              max_id=wNext_Id)
            if wRes['Result'] != True:
                return wRes  #失敗

            wGet_Toots = wRes['Responce']  #toot list(json形式)

            #############################
            # 新しいトゥートが取得できなかったらループ終了
            if len(wGet_Toots) > 0:
                wGetList += wGet_Toots
            else:
                break

            #############################
            # configの最大取得数を超えていたらループ終了
            if len(wGetList) >= wMax_Toots:
                break

            #############################
            # ページネーション(次の40件を取得する設定)
            try:
                wNext_Id = wGet_Toots[-1]['id']
            except:
                ###ありえない
                wRes[
                    'Reason'] = "CLS_Follow: __get_FollowerTL: Page nation error"
                wRes['Result'] = False
                return wRes

        #############################
        # IDに変換して詰める
        for wAccount in wGetList:
            ###変換
            wFulluser = CLS_UserData.sGetFulluser(wAccount['username'],
                                                  wAccount['url'])
            if wFulluser['Result'] != True:
                ###失敗 : 今のところ通らないルート
                continue

            ###詰める
##			self.ARR_FollowerTL.append( wFulluser['Fulluser'] )
            self.ARR_FollowerTL.update(
                {wFulluser['Fulluser']: str(wAccount['id'])})

        return wRes
예제 #3
0
파일: regist.py 프로젝트: xfyer/lucibot
	def sRegistMastodon( cls, inFulluser, inMail, inPass ):
		#############################
		# 応答形式の取得(mastodon形式)
		#   "Result" : False, "Reason" : None, "Responce" : None
		wRes = CLS_Mastodon_Use.sGet_API_Resp()
		
		#############################
		# ドメイン抽出
		wSTR_user = CLS_UserData.sUserCheck( inFulluser )
		if wSTR_user['Result']!=True :
			wRes['Reason'] = wSTR_user['Reason']
			return wRes
		
		#############################
		# レジスト処理
		wGetPath = CLS_UserData.sGetUserPath( inFulluser )
		if wGetPath['Result']!=True :
			wRes['Reason'] = "CLS_Regist: sRegistMastodon: User path ng: " + wGetPath['Reason']
			return wRes
		
		wRes = CLS_Mastodon_Use.create_app(
			client_name  = gVal.STR_SystemInfo['Client_Name'],
			api_base_url = "https://" + wSTR_user['Domain'],
			to_file = wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_RegFile'] )
		
		if wRes['Result']!=True :
			return wRes
		
		wMastodon = CLS_Mastodon_Use(
			client_id = wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_RegFile'],
			api_base_url = "https://" + wSTR_user['Domain'] )
		
		wIniStatus = wMastodon.GetIniStatus()
		if wIniStatus['Result']!=True :
			wRes['Reason'] = "CLS_Regist: sRegistMastodon: Create Mastodon object failuer: " + wIniStatus['Reason']
			return wRes		#mastodon error
		
		wRes = wMastodon.log_in(
			username = inMail,
			password = inPass,
			to_file = wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_UserFile'] )
		
		return wRes		#応答形式(mastodon形式)
예제 #4
0
    def __init__(self, parentObj=None):
        if parentObj == None:
            ###親クラス実体の未設定
            CLS_OSIF.sPrn(
                "CLS_Trend: __init__: You have not set the parent class entity for parentObj"
            )
            return

        self.Obj_Parent = parentObj
        self.FLG_Valid = CLS_UserData.sCheckTrafficUser(
            self.Obj_Parent.CHR_Account)
        self.__run()  #処理開始
        return
예제 #5
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
예제 #6
0
파일: bot_ctrl.py 프로젝트: xfyer/lucibot
    def __init__(self):
        #############################
        # ジョブクラスの生成
        self.OBJ_Job = CLS_Botjob()

        #############################
        # ユーザ一覧取得
        wUserList = CLS_UserData.sGetUserList()

        #############################
        # クラス変数に辞書型として納める
        self.UserList = {}
        for wUser in wUserList:
            self.UserList.update({wUser: False})

##		###バックグラウンドユーザの追加
##		self.UserList.update({ gVal.DEF_CRON_ACCOUNT_BACKGROUND : False })
        return
예제 #7
0
    def __run(self):
        #############################
        # 監視ユーザ設定済か
        if gVal.STR_MasterConfig['AdminUser'] == "":
            return

        #############################
        # 日付変更時間か
        if gVal.STR_TimeInfo['OneDay'] == False:
            return

        #############################
        # ハード監視ユーザか
        #   ・トラヒック監視ユーザの1番目か
        #   ・1番目がMasuerUserの場合は2番目か
        if CLS_UserData.sCheckHardUser(self.Obj_Parent.CHR_Account) != True:
            return

        # 監視確定
        #############################
        # 開始ログ
        self.Obj_Parent.OBJ_Mylog.Log('b', self.CHR_LogName + " 開始")

        #############################
        # SSL証明書情報
        self.SSL_Info()

        #############################
        # ハード情報
        self.Hard_Info()

        self.STR_Info['Result'] = True
        #############################
        # 処理結果ログ
        wStr = self.CHR_LogName + " 結果: 結果=" + str(self.STR_Info['Result'])

        if gVal.FLG_Test_Mode == False:
            self.Obj_Parent.OBJ_Mylog.Log('b', wStr)
        else:
            self.Obj_Parent.OBJ_Mylog.Log('b', wStr, True)

        return
예제 #8
0
    def __getCommand(self, inKind, inAccount):
        #############################
        # 応答形式の取得
        #   "Result" : False, "Reason" : None, "Responce" : None
        wRes = CLS_OSIF.sGet_Resp()

        #############################
        # cronが有効か?
        if self.OBJ_CronCtrl.Check() != True:
            wRes['Reason'] = "Cron disable"
            return wRes

        #############################
        # inKindが有効か?
        if inKind not in gVal.STR_CronInfo:
            wRes['Reason'] = "inKind is disable: " + inKind
            return wRes

        #############################
        # 登録のあるアカウントか?
        if inKind == gVal.DEF_CRON_MASTER or inKind == gVal.DEF_CRON_SUB:
            wUserList = CLS_UserData.sGetUserList()
            if inAccount not in wUserList:
                wRes['Reason'] = "Unregistered account: " + inAccount
                return wRes

        #############################
        # コマンドの組み立て
        if inKind == gVal.DEF_CRON_MASTER or inKind == gVal.DEF_CRON_SUB:
            wRes['Responce'] = self.Command_Temp + inKind + " " + inAccount
##		elif inKind==gVal.DEF_CRON_BACK :
##			wRes['Responce'] = self.Command_Temp + inKind + " " + gVal.DEF_CRON_ACCOUNT_BACKGROUND
        else:
            wRes['Responce'] = "Type that can not issue command: " + inKind
            return wRes

        wRes['Result'] = True
        return wRes
예제 #9
0
파일: regist.py 프로젝트: xfyer/lucibot
	def Test( self, inFulluser=None ):
		#############################
		# ユーザ名がない場合、名前を入力する
		if inFulluser==None :
			wStr = "通信テストをおこないます。" + '\n'
			wStr = wStr + "テストするユーザ名をドメインを含めて入力してください。 例= " + gVal.DEF_EXAMPLE_ACCOUNT
			CLS_OSIF.sPrn( wStr )
			inFulluser = CLS_OSIF.sInp( "User?=> " )
		
		#############################
		# 応答形式の取得(mastodon形式)
		#   "Result" : False, "Reason" : None, "Responce" : None
		wRes = CLS_Mastodon_Use.sGet_API_Resp()
		
		#############################
		# ユーザ名の妥当性チェック
		wSTR_user = CLS_UserData.sUserCheck( inFulluser )
		if wSTR_user['Result']!=True :
			wRes['Reason'] = wSTR_user['Reason']
			return wRes
		elif wSTR_user['Registed']==False :
			wRes['Reason'] = "登録されていないユーザです。: " + inFulluser
			return wRes
		
		self.__prn( "通信テスト中..." )
		#############################
		# 通信テスト
		wRes = self.CreateMastodon( inFulluser )
		if wRes['Result']!=True :
			wStr = "mastodonとの通信テストに失敗しました" + '\n'
			wStr = wStr + "メールアドレス、パスワード、mastodonが運用中か確認してください。" + '\n'
			wStr = wStr + wRes['Reason'] + '\n'
			self.__prn( wStr )
			return wRes
		
		self.__prn( "テスト完了。通信は正常です。" + '\n' )
		return wRes
예제 #10
0
파일: toot.py 프로젝트: xfyer/lucibot
    def MulticastToot(self):
        #############################
        # 同報配信ユーザ一覧の取得
        ##		wCLS_Config = CLS_Config()
        ##		wRes = wCLS_Config.GetMulticastUserList()
        ##		if wRes['Result']!=True :
        ##			CLS_OSIF.sPrn( "同報配信一覧の取得に失敗しました。" )
        ##			return False
        ##		elif len(wRes['Responce'])==0 :
        ##			CLS_OSIF.sPrn( "同報配信先がありません。" )
        ##			return False
        ##
        ##		wMulticastList = wRes['Responce']

        wMulticastList = CLS_UserData.sGetUserList()
        ##		elif len( wMulticastList )==0 :
        if len(wMulticastList) == 0:
            CLS_OSIF.sPrn("同報配信先がありません。")
            return False

        #############################
        # MasterUserユーザチェック
        wFulluser = gVal.STR_MasterConfig['MasterUser']
        wSTR_user = CLS_UserData.sUserCheck(wFulluser)
        if wSTR_user['Result'] != True:
            ###config書き換えたかなんかしたろ?
            CLS_OSIF.sPrn("CLS_Toot: MulticastToot: Failer user name: " +
                          wFulluser)
            return False

        CLS_OSIF.sPrn("mastodonと通信中...")
        #############################
        # mastodonクラス生成
        wCLS_work = CLS_Regist()
        wRes = wCLS_work.CreateMastodon(wFulluser)
        if wRes['Result'] != True:
            CLS_OSIF.sPrn("mastodonと接続できないため中止します。 domain=" +
                          wSTR_user['Domain'])
            return False

        CLS_OSIF.sPrn("同報配信先一覧の作成中...")
        #############################
        # 配信先一覧(MasterUser)
        wSendList = {}
        wSendList.update({wFulluser: ""})
        wSendList[wFulluser] = {}
        wSendList[wFulluser].update({"fulluser": wFulluser})
        wSendList[wFulluser].update({"domain": wSTR_user['Domain']})

        #############################
        # 同報配信先ユーザのクラス作成
        for wUser in wMulticastList:
            #############################
            # ユーザチェック
            wSTR_user = CLS_UserData.sUserCheck(wUser)
            if wSTR_user['Result'] != True:
                continue

            #############################
            # mastodonクラス生成
            wRes = wCLS_work.CreateMastodon(wUser)
            if wRes['Result'] != True:
                continue

            #############################
            # 配信先一覧
            wSendList.update({wUser: ""})
            wSendList[wUser] = {}
            wSendList[wUser].update({"fulluser": wUser})
            wSendList[wUser].update({"domain": wSTR_user['Domain']})

        #############################
        # 配信先数のチェック
        if len(wSendList) <= 1:
            CLS_OSIF.sPrn("接続可能な同報配信先がありません。")
            return False

        #############################
        # コンソール
        while True:
            #############################
            # コマンド画面表示
            wCommand = self.__multicastToot_Disp(wFulluser, len(wSendList))

            #############################
            # 継続
            if wCommand == "":
                continue

            #############################
            # 終了
            elif wCommand.find("\\q") >= 0:
                break

            #############################
            # 範囲切り替え
            elif wCommand.find("\\c") >= 0:
                self.SetRange('Multicast')

            #############################
            # 一覧
            elif wCommand.find("\\l") >= 0:
                self.__multicastList(wSendList)

            #############################
            # (ないコマンド)
            elif wCommand.find("\\") == 0:
                wStr = "そのコマンドはありません。[RT]"
                CLS_OSIF.sInp(wStr)
                continue

            #############################
            # トゥート
            else:
                self.__multicastToot(wFulluser, wSendList, wCommand, wCLS_work)

        return
예제 #11
0
파일: lookhtl.py 프로젝트: h3zjp/lucibot
    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
예제 #12
0
파일: regist.py 프로젝트: xfyer/lucibot
	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
예제 #13
0
파일: regist.py 프로젝트: xfyer/lucibot
	def CreateMastodon( self, inFulluser ):
		#############################
		# 応答形式の取得(mastodon形式)
		#   "Result" : False, "Reason" : None, "Responce" : None
		wRes = CLS_Mastodon_Use.sGet_API_Resp()
		
		#############################
		# 出力先領域のチェック
			#辞書型か?
		if isinstance( self.STR_Mastodon, dict )!=True :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: STR_Mastodon is not dict: type= " + type(self.STR_Mastodon)
			return wRes
		
			#重複してるか?
		if inFulluser in self.STR_Mastodon :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: Overlap user: "******"CLS_Regist: CreateMastodon: Domain check error: " + inFulluser
			return wRes
		
		#############################
		# ping疎通チェック
		if CLS_OSIF.sPing( wSTR_user['Domain'] )!=True :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: Ping check error: " + wSTR_user['Domain']
			return wRes	#失敗
		
		#############################
		# レジストファイルの存在チェック
		wGetPath = CLS_UserData.sGetUserPath( inFulluser )
##		if wGetPath['Result']!=True :
##			wRes['Reason'] = "CLS_Regist: CreateMastodon: User path ng: " + wGetPath['Reason']
##			return wRes
		
		wRegFile = wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_RegFile']
		if CLS_File.sExist( wRegFile )!=True :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: Regist File not is found: " + wRegFile
			return wRes		#ファイルがない
		
		wUserFile = wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_UserFile']
		if CLS_File.sExist( wUserFile )!=True :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: Userreg File not is found: " + wUserFile
			return wRes		#ファイルがない
		
		#############################
		# mastodon APIオブジェクトを生成する
		self.STR_Mastodon.update({ inFulluser : CLS_Mastodon_Use(
			api_base_url = "https://" + wSTR_user['Domain'],
			client_id    = wRegFile,
			access_token = wUserFile ) })
###			flg_orginit=True ) })
		
		wIniStatus = self.STR_Mastodon[inFulluser].GetIniStatus()
		if wIniStatus['Result']!=True :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: Create Mastodon object failuer: " + wIniStatus['Reason']
			return wRes		#mastodon error
		
		#############################
		# 通信テスト(トークンチェック)
		if self.STR_Mastodon[inFulluser].TokenCheck()!=True :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: Mastodon Token is None (mastodon error): " + inFulluser
			return wRes		#ファイルがない
		
		wRes['Result'] = True
		return wRes
예제 #14
0
파일: crontest.py 프로젝트: xfyer/lucibot
    def Run(self):
        #############################
        # 応答形式の取得
        #   "Result" : False, "Reason" : None, "Responce" : None
        wRes = CLS_OSIF.sGet_Resp()

        #############################
        # 引数取得
        wArg = CLS_OSIF.sGetArg()
        if len(wArg) == 3:  #テストモードか
            if wArg[2] == gVal.DEF_TEST_MODE:
                gVal.FLG_Test_Mode = True

        elif len(wArg) != 2:  #引数が足りない
            wStr = "CLS_CronTest: Argument deficiency: argument=" + str(wArg)
            CLS_OSIF.sPrn(wStr)  #メールに頼る
            return wRes

        wKind = wArg[0]
        wAccount = wArg[1]

        ##		#############################
        ##		# Backgroundのチェックは別でやる
        ##		if wKind==gVal.DEF_CRON_BACK and wAccount==gVal.DEF_CRON_ACCOUNT_BACKGROUND :
        ##			wRes = self.__backgroundTest( outRes=wRes )
        ##			return wRes

        #############################
        # 1.jobチェック
        #     実行ファイルチェック
        #     ユーザ登録チェック(Master、Subの場合)
        wCLS_Botjob = CLS_Botjob()
        wRes = wCLS_Botjob.isJob(wKind, wAccount)
        if wRes['Result'] != True:
            wStr = "CLS_CronTest: Job check NG: " + wRes['Reason']
            CLS_OSIF.sPrn(wStr)  #メールに頼る
            return wRes

        if wRes['Responce']['isJob'] == False and gVal.FLG_Test_Mode == False:
            ##			wStr = "CLS_CronTest: Job is not found: kind=" + wKind + ": account=" + wAccount
            wStr = "CLS_CronTest: Job is not found: kind=" + wKind + ": account=" + wAccount + " current: " + CLS_OSIF.sGetCwd(
            )
            CLS_OSIF.sPrn(wStr)  #メールに頼る

            wRes['Result'] = False  #テストはNG
            return wRes

        wFlg_ok = True
        #############################
        # 2.データフォルダのチェック
        if CLS_File.sExist(gVal.DEF_USERDATA_PATH) != True:
            wFlg_ok = False

        #############################
        # 3.Master環境情報の読み込み
        if CLS_Config.sGetMasterConfig() != True:
            wFlg_ok = False

        #############################
        # Master環境情報に異常はないか
        if wFlg_ok == False:
            ##			wRes = wCLS_Botjob.Stop()	#全cronを削除する
            ##			if wRes['Result']!=True :
            ##				wStr = "CLS_CronTest: Cron stop failed: " + wRes['Reason']
            ##				CLS_OSIF.sPrn( wStr  )	#メールに頼る
            ##
            ##			wStr = "Master環境情報に異常があったため、" + gVal.STR_SystemInfo['Client_Name']
            ##			wStr = wStr + "で登録した全cronを停止しました。"
            wStr = "Master環境情報に異常があったため、処理を中止します。"
            CLS_OSIF.sPrn(wStr)  #メールに頼る

            wRes['Result'] = False  #テストはNG
            return wRes

        #############################
        # 4.Userフォルダチェック
        wRes = CLS_UserData.sGetUserPath(wAccount)
        if wRes['Result'] != True:
            wRes = wCLS_Botjob.Del(wKind, wAccount)  #cronを削除する
            if wRes['Result'] != True:
                wStr = "CLS_CronTest: Cron delete failed: " + wRes['Reason']
                CLS_OSIF.sPrn(wStr)  #メールに頼る

            wStr = "Userフォルダが存在しないため、" + wAccount
            wStr = wStr + "のcronを停止しました。"
            CLS_OSIF.sPrn(wStr)  #メールに頼る

            wRes['Result'] = False  #テストはNG
            return wRes

        wUserPath = wRes['Responce']

        ##		#############################
        ##		# 5.User環境情報の読み込み
        ##		wRes = CLS_Config.sGetUserConfig( wAccount )
        ##		if wRes['Result']!=True :
        ##			wRes = wCLS_Botjob.Del( wKind, wAccount )	#cronを削除する
        ##			if wRes['Result']!=True :
        ##				wStr = "CLS_CronTest: Cron delete failed: " + wRes['Reason']
        ##				CLS_OSIF.sPrn( wStr  )	#メールに頼る
        ##
        ##			wStr = "User環境情報に異常があったため、" + wAccount
        ##			wStr = wStr + "のcronを停止しました。"
        ##			CLS_OSIF.sPrn( wStr  )		#メールに頼る
        ##
        ##			wRes['Result'] = False	#テストはNG
        ##			return wRes

        #############################
        # 5.実行権限チェック
        wFlg_Authority = True
        #############################
        # コマンドの組み立て
        if wKind == gVal.DEF_CRON_MASTER:  # Masuer User以外か
            if wAccount != gVal.STR_MasterConfig['MasterUser']:
                wFlg_Authority = False

##		elif wKind==gVal.DEF_CRON_BACK :	# Background以外か
##			if wAccount!=gVal.DEF_CRON_ACCOUNT_BACKGROUND :
##				wFlg_Authority = False

        elif wKind == gVal.DEF_CRON_SUB:  # Sub以外か
            ##			if wAccount==gVal.STR_MasterConfig['MasterUser'] or \
            ##			   wAccount==gVal.DEF_CRON_ACCOUNT_BACKGROUND :
            if wAccount == gVal.STR_MasterConfig['MasterUser']:
                wFlg_Authority = False

        else:
            ###ここではありえない
            wFlg_Authority = False

        if wFlg_Authority == False:
            wRes = wCLS_Botjob.Del(wKind, wAccount)  #cronを削除する
            if wRes['Result'] != True:
                wStr = "CLS_CronTest: Cron delete failed: " + wRes['Reason']
                CLS_OSIF.sPrn(wStr)  #メールに頼る

            wStr = "実行権限に問題があったため、" + wAccount
            wStr = wStr + "のcronを停止しました。"
            CLS_OSIF.sPrn(wStr)  #メールに頼る

            wRes['Result'] = False  #テストはNG
            return wRes

        # ここまででtestは合格してる
        #############################

        #############################
        # 6.testログ
        self.__testLog(wKind, wAccount)

        wRes['Responce'] = {}
        wRes['Responce'].update({
            "Kind": wKind,
            "Account": wAccount,
            "User_path": wUserPath
        })
        wRes['Result'] = True
        return wRes
예제 #15
0
파일: regist.py 프로젝트: xfyer/lucibot
	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
예제 #16
0
파일: regist.py 프로젝트: xfyer/lucibot
	def Regist( self, inFulluser=None ):
		#############################
		# ユーザ名がない場合、名前を入力する
		if inFulluser==None :
			wStr = gVal.STR_SystemInfo['Client_Name'] + " に新しいユーザ名を入力します。" + '\n'
			wStr = wStr + "登録するユーザ名をドメインを含めて入力してください。 例= " + gVal.DEF_EXAMPLE_ACCOUNT
			CLS_OSIF.sPrn( wStr )
			inFulluser = CLS_OSIF.sInp( "User?=> " )
		
		#############################
		# ユーザ名の妥当性チェック
		wSTR_user = CLS_UserData.sUserCheck( inFulluser )
		if wSTR_user['Result']!=True :
			CLS_OSIF.sPrn( wSTR_user['Reason'] )
			return False
		elif wSTR_user['Registed']==True :
			CLS_OSIF.sPrn( "既に登録されているユーザです。: " + inFulluser )
			return False
		
		#############################
		# メールアドレス、パスワードの入力
		wStr = '\n' + inFulluser + " を登録します。"
		wStr = wStr + "mastodonに登録したメールアドレスとパスワードを入力してください。"
		CLS_OSIF.sPrn( wStr )
		
		###入力受け付け
		wMail = CLS_OSIF.sInp( "Mailaddr: " )
		wPass = CLS_OSIF.sGpp( "Password: "******"mastodon ID: " + inFulluser + '\n'
		wStr = wStr + "Mailaddress: " + wMail
		CLS_OSIF.sPrn( wStr )
		wRes = CLS_OSIF.sInp( "以上の内容で登録します(y/N): " )
		if wRes!="y" :
			CLS_OSIF.sPrn( "登録を中止しました" + '\n' )
			return False
		
		#############################
		# 入力チェック
		wRes = self.__registUser( inFulluser, wMail, wPass )
		if wRes['Result']!=True :
			CLS_OSIF.sPrn( wRes['Reason'] )
			return False
		
		CLS_OSIF.sPrn( '\n' + "通信テスト中..." )
		#############################
		# mastodonアクセス前 ping疎通チェック
		if CLS_OSIF.sPing( wSTR_user['Domain'] )!=True :
			CLS_OSIF.sPrn( "mastodonサーバ " + wSTR_user['Domain'] + " が応答しません。登録を中止します。" )
			return False
		
		CLS_OSIF.sPrn( "通信OK" + '\n' + "データ登録中......" )
		#############################
		# テンプレートデータのコピー(データ作成)
		wGetPath = CLS_UserData.sGetUserPath( inFulluser )
##		if wGetPath['Result']!=True :
##			CLS_OSIF.sPrn( "CLS_Regist: Regist: User path ng: " + wGetPath['Reason'] )
##			return False
		
		if CLS_File.sCopytree(
			gVal.DEF_STR_FILE['defUserdata_path'],
			wGetPath['Responce'] )!=True :
			###ありえない
			CLS_OSIF.sPrn( "CLS_Regist: Regist: defaultデータコピー失敗" )
			return False
		
		if CLS_File.sFolderExist( gVal.DEF_USERDATA_PATH, inFulluser )!=True :
			CLS_OSIF.sPrn( "CLS_Regist: Regist: ユーザデータの登録に失敗しました" )
			return False
		
		#############################
		# mastodonアカウントへの関連付け(本レジスト)
		wRes = self.sRegistMastodon( inFulluser, wMail, wPass )
		if wRes['Result']!=True :
			wStr = "mastodonへの関連付けに失敗しました" + '\n'
			wStr = wStr + "メールアドレス、パスワード、mastodonが運用中か確認してください。" + '\n'
			wStr = wStr + wRes['Reason']
			CLS_OSIF.sPrn( wStr )
			# データ削除
			CLS_File.sRmtree( wGetPath['Responce'] )
			return False
		
		CLS_OSIF.sPrn( "登録OK" + '\n' + "mastodon登録テスト中......" )
		#############################
		# 通信テスト
		wRes = self.CreateMastodon( inFulluser )
		if wRes['Result']!=True :
			wStr = "mastodonへの関連付けに失敗しました" + '\n'
			wStr = wStr + "メールアドレス、パスワード、mastodonが運用中か確認してください。" + '\n'
			wStr = wStr + wRes['Reason']
			CLS_OSIF.sPrn( wStr )
			# データ削除
			CLS_File.sRmtree( wGetPath['Responce'] )
			return False
		
		CLS_OSIF.sPrn( "mastodon登録OK" + '\n' )
		
		#############################
		# cron作成
		if inFulluser == gVal.STR_MasterConfig['MasterUser'] :
			wKind = gVal.DEF_CRON_MASTER
		else:
			wKind = gVal.DEF_CRON_SUB
		
		wCLS_botjib = CLS_Botjob()
		wPutRes = wCLS_botjib.Put( wKind, inFulluser )
		if wPutRes['Result']!=True :
##			CLS_OSIF.sPrn( "CLS_Regist: Regist: cron create failed: " + wPutRes['Reason'] )
##			return False
##		
##		CLS_OSIF.sPrn( '\n' + "cronを起動しました" )
			CLS_OSIF.sPrn( "cronの起動に失敗しました: " + wPutRes['Reason'] )
		else :
			CLS_OSIF.sPrn( '\n' + "cronを起動しました" )
		
		#############################
		# トラヒックの登録
		wRes = self.__regTrafficUser( inFulluser )
		if wRes['Result']!=True :
			CLS_OSIF.sPrn( "CLS_Regist: Regist: " + wRes['Reason'] )
			return False
		if wRes['Update']==True :
			CLS_OSIF.sPrn( "DBにトラヒック情報が追加されました" )
		
		#############################
		# 完了
		CLS_OSIF.sPrn( inFulluser + " の登録が完了しました" + '\n' )
		return True
예제 #17
0
	def AllInit(self):
		#############################
		# フォルダの存在チェック
		if CLS_File.sExist( gVal.DEF_STR_FILE['MasterConfig_path'] )!=True :
			CLS_OSIF.sPrn( "CLS_Config: Init: Master Data is not Exist" )
			return False	#失敗
		
		#############################
		# Master環境情報の変更
		wStr = "データベースと全ての作業ファイルをクリアします。" + '\n'
		wStr = wStr + "よろしいですか?(y/N)=> "
		wSelect = CLS_OSIF.sInp( wStr )
		if wSelect!="y" :
			##キャンセル
			CLS_OSIF.sInp( "リターンキーを押して再度コンソールアプリを起動してください。[RT]" )
			return True
		
		CLS_OSIF.sPrn( "cronを停止中。2分ほどお待ちください..." + '\n' )
		#############################
		# ユーザ一覧取得
		wUserList = CLS_UserData.sGetUserList()
		
		#############################
		# cronの停止
##		wCLS_Botjob = CLS_Botjob()
		wCLS_Bot_Ctrl = CLS_Bot_Ctrl()
		wFlg_CronStop = wCLS_Bot_Ctrl.CronAllStop()
		if wFlg_CronStop==True :
			### 停止したbotあり
			CLS_OSIF.sSleep(120)	#とりあえずcronが停止する2分は待つ
		
##		wFLG_Wait = False
##		wWaitRestart = {}
##		wIndex       = 0
##		for wUser in wUserList :
##			#############################
##			# 種別を判定
##			if gVal.STR_MasterConfig['MasterUser']==wUser :
##				wKind = gVal.DEF_CRON_MASTER
##			else :
##				wKind = gVal.DEF_CRON_SUB
##			
##			#############################
##			# ジョブの削除
##			wRes = wCLS_Botjob.Del( wKind, wUser )
##			if wRes['Result']!=True :
##				###おそらく動いてないcronのためスキップ
##				continue
##			
##			#############################
##			# 停止cronをメモ
##			wWaitRestart.update({ wIndex : wIndex })
##			wWaitRestart[wIndex] = {}
##			wWaitRestart[wIndex].update({ "Kind" : wKind })
##			wWaitRestart[wIndex].update({ "User" : wUser })
##			wFLG_Wait  = True
##			wIndex    += 1
##		
##		#############################
##		# 1つでも停止cronがあれば2分待つ
##		if wFLG_Wait==True :
##			CLS_OSIF.sSleep(120)
		
		CLS_OSIF.sPrn( "各ユーザの作業ファイルを初期化しています..." + '\n' )
		#############################
		# ファイルの初期化(各ユーザ)
		for wUser in wUserList :
			CLS_OSIF.sPrn( "ユーザ " + wUser + " 初期化中..." )
			
			#############################
			# ユーザフォルダチェック
			wRes = CLS_UserData.sGetUserPath( wUser )
			if wRes['Result']!=True :
				CLS_OSIF.sPrn( "CLS_Setup: Init: User folder is not Exist: user="******"masterConfig 初期化中..." + '\n' )
		#############################
		# ドメイン情報
		wDefFile_path = gVal.DEF_STR_FILE['defMasterdata_path'] + gVal.DEF_STR_FILE['MstdnDomains_File']
		wDstFile_path = gVal.DEF_STR_FILE['MasterConfig_path'] + gVal.DEF_STR_FILE['MstdnDomains_File']
		self.__initFile( wDefFile_path, wDstFile_path )
		
		#############################
		# 過去ツイート
		wDefFile_path = gVal.DEF_STR_FILE['defMasterdata_path'] + gVal.DEF_STR_FILE['TweetFile']
		wDstFile_path = gVal.DEF_STR_FILE['MasterConfig_path'] + gVal.DEF_STR_FILE['TweetFile']
		self.__initFile( wDefFile_path, wDstFile_path )
		
		#############################
		# 周期トゥート
		wDefFile_path = gVal.DEF_STR_FILE['defMasterdata_path'] + gVal.DEF_STR_FILE['CLDataFile']
		wDstFile_path = gVal.DEF_STR_FILE['MasterConfig_path'] + gVal.DEF_STR_FILE['CLDataFile']
		self.__initFile( wDefFile_path, wDstFile_path )
		
	#############################
		CLS_OSIF.sPrn( "データベースを初期化しています..." + '\n' )
		#############################
		# DBの初期化
		wFLG_Init = True
		### 初期化
		if self.__initDB()!=True :
			wFLG_Init = False
		### 修復
		if self.__recovery_TBL_TRAFFIC_DATA()!=True :
			wFLG_Init = False
		
		if wFLG_Init==True :
			CLS_OSIF.sPrn( "データベースの初期化をおこないました" + '\n' )
		else :
			##ありえない
			CLS_OSIF.sPrn( "*** データベースの初期化に失敗しました" + '\n' )
		
		#############################
		# cronの再起動
##		if wFLG_Wait==True :
##			CLS_OSIF.sPrn( "停止していたcronを再開します..." + '\n' )
##			
##			wKeylist = wWaitRestart.keys()
##			for wKey in wKeylist :
##				#############################
##				# ジョブの登録
##				wRes = wCLS_Botjob.Put( wWaitRestart[wKey]["Kind"], wWaitRestart[wKey]["User"] )
##				if wRes['Result']!=True :
##					###失敗
##					CLS_OSIF.sPrn( "cronの起動に失敗しました: user="******"User"] + '\n' )
##		
		if wFlg_CronStop==True :
			### 停止したbotあり
			CLS_OSIF.sPrn( "停止していたcronを再開します..." + '\n' )
			wCLS_Bot_Ctrl.CronReStart()
		
		#############################
		# 終わり
		CLS_OSIF.sPrn( "初期化が正常終了しました。" )
##		CLS_OSIF.sInp( "リターンキーを押して再度コンソールアプリを起動してください。[RT]" )
		return True
예제 #18
0
    def sRunCommand(cls, inCommand):

        wCLS_work = ""
        wFlg = False

        #####################################################
        #############################
        # システム情報の表示
        ##		if inCommand=="-v" :
        if inCommand == "\\v":
            cls().sView_Sysinfo()
            wFlg = True
        #############################
        # Master環境情報の表示
##		elif inCommand=="-vm" :
        elif inCommand == "\\vm":
            wCLS_work = CLS_Config()
            wCLS_work.MasterConfig_Disp()
            wFlg = True

    #####################################################
    #############################
    # Master環境情報の表示・操作
##		elif inCommand=="-c" :
        elif inCommand == "\\c":
            wCLS_work = CLS_Config()
            wCLS_work.CnfMasterConfig()
            wFlg = True
        #############################
        # MasterUserの変更
##		elif inCommand=="-cm" :
        elif inCommand == "\\cm":
            wCLS_work = CLS_Config()
            wCLS_work.CnfMasterUser()
            wFlg = True
        #############################
        # AdminUserの変更
##		elif inCommand=="-ca" :
        elif inCommand == "\\ca":
            wCLS_work = CLS_Config()
            wCLS_work.CnfAdminUser()
            wFlg = True

    #####################################################
    #############################
    # ユーザ登録 一覧表示
##		elif inCommand=="-u" :
        elif inCommand == "\\u":
            wCLS_work = CLS_UserData()
            wCLS_work.ViewUserList()
            wFlg = True

        #############################
        # ユーザ登録 登録
##		elif inCommand=="-ur" :
        elif inCommand == "\\ur":
            wCLS_work = CLS_Regist()
            wCLS_work.Regist()
            wFlg = True

        #############################
        # ユーザ登録 再登録
##		elif inCommand=="-uu" :
        elif inCommand == "\\uu":
            wCLS_work = CLS_Regist()
            wCLS_work.Update()
            wFlg = True

        #############################
        # ユーザ登録 削除
##		elif inCommand=="-ud" :
        elif inCommand == "\\ud":
            wCLS_work = CLS_Regist()
            wCLS_work.Delete()
            wFlg = True
        #############################
        # User環境情報の表示・操作
##		elif inCommand=="-uc" :
        elif inCommand == "\\uc":
            wCLS_work = CLS_Config()
            wCLS_work.CnfUserConfig()
            wFlg = True

    #####################################################
    #############################
    # 手動トゥートモード
##		elif inCommand=="-t" :
        elif inCommand == "\\t":
            wCLS_work = CLS_Toot()
            wCLS_work.ManualToot()
            wFlg = True

        #############################
        # 同報配信トゥートモード
##		elif inCommand=="-tm" :
        elif inCommand == "\\tm":
            wCLS_work = CLS_Toot()
            wCLS_work.MulticastToot()
            wFlg = True

        #############################
        # Twitterモード
##		elif inCommand=="-tw" :
        elif inCommand == "\\tw":
            wCLS_work = CLS_Toot()
            wCLS_work.ManualTweet()
            wFlg = True

    #####################################################
    #############################
    # 通信テスト
##		elif inCommand=="-test" :
        elif inCommand == "\\test":
            wCLS_work = CLS_Regist()
            wCLS_work.Test()
            wFlg = True

        #############################
        # DBエディタ
##		elif inCommand=="-vdb" :
        elif inCommand == "\\vdb":
            wCLS_work = CLS_DBedit()
            wCLS_work.View()
            wFlg = True

    #####################################################
    #############################
    # master運用操作
##		elif inCommand=="-run" :
        elif inCommand == "\\run":
            wCLS_work = CLS_Bot_Ctrl()
            wCLS_work.Console()
            wFlg = True
        #############################
        # Twitter連携
##		elif inCommand=="-ct" :
        elif inCommand == "\\ct":
            wCLS_Twitter = CLS_Twitter_Use()
            wCLS_Twitter.CreateTwitter(gVal.DEF_STR_FILE['Twitter_File'],
                                       gVal.DEF_STR_FILE['defTwitter_File'])
            wCLS_work = CLS_Config()
            wCLS_work.CnfTwitter()  #有効無効設定

            ##タイムラインの設定
            CLS_OSIF.sPrn('\n' + "Twitterと接続しています......")
            wCLS_Twitter = CLS_Twitter_Use(gVal.DEF_STR_FILE['Twitter_File'],
                                           gVal.DEF_STR_TLNUM['getTwitTLnum'])
            if gVal.STR_MasterConfig['Twitter'] == "on":
                wCLS_Twitter.CnfTimeline(gVal.DEF_STR_FILE['Twitter_File'])

            wFlg = True

        return wFlg
예제 #19
0
    def __run(self):
        #############################
        # 開始ログ
        self.Obj_Parent.OBJ_Mylog.Log('b', self.CHR_LogName + " 開始")

        #############################
        # Twitterリーダ パターン読み込み
        if self.__getTwitterPatt() != True:
            return

        #############################
        # トレンドの送信
        if gVal.FLG_Test_Mode == False:
            # 1時間経ってる周回か
            if gVal.STR_TimeInfo['OneHour']==True and \
               self.CHR_TrendSender==self.Obj_Parent.CHR_Account :
                self.Send_Trend()
        else:
            ###テストモード時
            if self.CHR_TrendSender == self.Obj_Parent.CHR_Account:
                self.Send_Trend()

        #############################
        # Twitterから取得
        #   ハード監視ユーザ 1つのみで実行
        if CLS_UserData.sCheckHardUser(self.Obj_Parent.CHR_Account) == True:
            #############################
            # 送信済レコードを削除
            # ・1時間経ってる周回か
            if gVal.STR_TimeInfo['OneHour'] == True:
                self.Delete_DBctrl_Twitter()

            #############################
            # Twitterタイムライン取得
            if self.Get_TwitterTL() != True:
                return

            #############################
            # 過去TLの読み込み
            wRes = self.Get_RateTwitterTL()
            if wRes != True:
                self.Obj_Parent.OBJ_Mylog.Log(
                    'a', "CLS_TwitterReader: __run: Get_RateTwitterTL failed")
                return
            if len(self.ARR_RateTL) == 0:
                self.Init_RateTwitterTL()
                if gVal.FLG_Test_Mode == False:
                    self.Obj_Parent.OBJ_Mylog.Log(
                        'b', self.CHR_LogName + " Twitter過去TL初期化")
                else:
                    self.Obj_Parent.OBJ_Mylog.Log('b',
                                                  self.CHR_LogName +
                                                  " Twitter過去TL初期化",
                                                  inView=True)
                return

            #############################
            # 新規ツイートを辞書に収める
            self.ARR_Twitter = {}
            wIndex = 0

            self.ARR_UpdateTL = []
            for wROW in self.ARR_NewTL:
                #############################
                # チェックするので新過去TLに保管
                self.ARR_UpdateTL.append(wROW['id'])

                #############################
                # 過去チェックしたトゥートはスキップ
                wFlg_Rate = False
                for wRow_Rate in self.ARR_RateTL:
                    if str(wRow_Rate) == str(wROW['id']):
                        wFlg_Rate = True
                        break

                if wFlg_Rate == True:
                    continue

                #############################
                # パターンチェック
                wRes_check = self.__checkTwitterPatt(wROW)
                if wRes_check['result'] != True:
                    continue

                #############################
                # 格納
                self.ARR_Twitter.update({wIndex: ""})
                self.ARR_Twitter[wIndex] = {}
                self.ARR_Twitter[wIndex].update({"id": str(wROW['id'])})
                self.ARR_Twitter[wIndex].update({"text": str(wROW['text'])})
                self.ARR_Twitter[wIndex].update(
                    {"screen_name": str(wROW['user']['screen_name'])})
                self.ARR_Twitter[wIndex].update(
                    {"send_user": wRes_check['send_user']})
                self.ARR_Twitter[wIndex].update({"tags": wRes_check['tags']})
                self.ARR_Twitter[wIndex].update({"lupdate": ""})
                self.ARR_Twitter[wIndex].update({"sended": False})
                #更新時間 (twitter時間)
                wTime = CLS_OSIF.sGetTimeformat_Twitter(wROW['created_at'])
                if wTime['Result'] != True:
                    self.Obj_Parent.OBJ_Mylog.Log(
                        'a',
                        "CLS_TwitterReader: __run: sGetTimeformat_Twitter is failed"
                    )
                    continue
                self.ARR_Twitter[wIndex]['lupdate'] = wTime['TimeDate']

                wIndex += 1
                self.STR_Cope["Now_Cope"] += 1

            #############################
            # 新・過去LTL保存
            wRes = self.Set_RateTwitterTL()
            if wRes != True:
                self.Obj_Parent.OBJ_Mylog.Log(
                    'a', "CLS_TwitterReader: __run: Set_RateTwitterTL failed")
                return

            #############################
            # DBに格納
            self.Set_DBctrl_Twitter()

        #############################
        # トゥート送信
        self.Send_Toot()

        #############################
        # 処理結果ログ
        wStr = self.CHR_LogName + " 結果: Cope=" + str(self.STR_Cope['Now_Cope'])
        wStr = wStr + " Twitter=" + str(self.STR_Cope['Twitter'])
        wStr = wStr + " Sended=" + str(self.STR_Cope['Sended'])
        wStr = wStr + " DB=[Insert:" + str(
            self.STR_Cope['Insert']) + " Update:" + str(
                self.STR_Cope['Update']) + " Delete:" + str(
                    self.STR_Cope['Delete']) + "]"
        if self.STR_Cope['TrendSended'] > 0:
            wStr = wStr + " Trend Sended"

        if gVal.FLG_Test_Mode == False:
            self.Obj_Parent.OBJ_Mylog.Log('b', wStr)
        else:
            self.Obj_Parent.OBJ_Mylog.Log('b', wStr, inView=True)

        return
예제 #20
0
파일: logarcive.py 프로젝트: xfyer/lucibot
	def Run(self):
		#############################
		# 処理開始の確認
		wStr = "ログのアーカイブを開始します。" + '\n'
		wStr = wStr + "よろしいですか?(y/N)=> "
		wRes = CLS_OSIF.sInp( wStr )
		if wRes!="y" :
			CLS_OSIF.sPrn( "処理を中止しました。" )
			return
		
		#############################
		# ユーザフォルダのアーカイブリスト 作成
		wARR_UserList = CLS_UserData.sGetUserList()
		wARR_ArciveList = []
		wARR_DeleteList = {}
		wIndex = 0
		for wLine in wARR_UserList :
			#############################
			# パス生成
			wPath = gVal.DEF_USERDATA_PATH + wLine + "/log/"
			wARR_ArciveList.append( wPath )
			
			#############################
			# ファイル一覧生成
			wFileList = CLS_File.sFs( wPath )
			wDelList = []
			for wFilePath in wFileList :
##				wFilePath = wPath + wFilePath
				wARR_ArciveList.append( wFilePath )
				wDelList.append( wFilePath )
			
			wARR_DeleteList.update({ wIndex : wDelList })
			wIndex += 1
		
		#############################
		# masterConfigフォルダ 追加
		wPath = gVal.DEF_USERDATA_PATH + gVal.DEF_MASTERCONFIG_NAME + "/log/"
		wARR_ArciveList.append( wPath )
		
		wFileList = CLS_File.sFs( wPath )
		wDelList = []
		for wFilePath in wFileList :
##			wFilePath = wPath + wFilePath
			wARR_ArciveList.append( wFilePath )
			wDelList.append( wFilePath )
		
##		wARR_DeleteList.update({ wIndex : wDelList })
##		wIndex += 1
		
		#############################
		# 各カレントの削除一覧から最後尾を抜く
		wKeyList = wARR_DeleteList.keys()
		for wKey in wKeyList :
			if len(wARR_DeleteList[wKey])>=2 :
				del wARR_DeleteList[wKey][-1]
		
		#############################
		# アーカイブ名の作成
		
		#############################
		# 時間を取得
		wTD = CLS_OSIF.sGetTime()
		if wTD['Result']!=True :
			###時間取得失敗  時計壊れた?
			CLS_OSIF.sPrn( "時間取得失敗。処理を中止しました。" )
			return
		wDate = wTD['TimeDate'].split(" ")
		
		#############################
		# ファイルパスを作成する
##		wLogFile = gVal.DEF_STR_FILE['MasterLog_path'] + "logs" + wDate[0] + wDate[1] + ".zip"
		wNDate = wDate[0].replace( "-", "" )
		wNTime = wDate[1].replace( ":", "" )
		wFileName = "logs_" + wNDate + "_" + wNTime + ".zip"
		wLogFile = gVal.DEF_STR_FILE['MasterConfig_path'] + wFileName
		
		CLS_OSIF.sPrn( '\n' + "アーカイブ実行中..." )
		#############################
		# アーカイブ実行
###		print( "xx1: " + wLogFile )
###		print( "xx2: " + str(wARR_ArciveList) )
		if CLS_File.sFolderArcive( wLogFile, wARR_ArciveList )!=True :
			CLS_OSIF.sPrn( "アーカイブ失敗。処理を中止しました。" )
			return
		
		CLS_OSIF.sPrn( '\n' + "古いログを削除中..." )
		#############################
		# 古いログを削除
		wKeyList = wARR_DeleteList.keys()
		for wKey in wKeyList :
			for wPath in wARR_DeleteList[wKey] :
###				print( wPath )
				if CLS_File.sRemove( wPath )!=True :
					CLS_OSIF.sPrn( "削除失敗。処理を中止しました。" )
					break
		
		CLS_OSIF.sPrn( "処理が完了しました。" )
		return
예제 #21
0
파일: circletoot.py 프로젝트: h3zjp/lucibot
    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
예제 #22
0
파일: toot.py 프로젝트: xfyer/lucibot
    def ManualToot(self):
        #############################
        # MasterUserユーザチェック
        wFulluser = gVal.STR_MasterConfig['MasterUser']
        wSTR_user = CLS_UserData.sUserCheck(wFulluser)
        if wSTR_user['Result'] != True:
            ###config書き換えたかなんかしたろ?
            CLS_OSIF.sPrn("CLS_Toot: ManualToot: Failer user name: " +
                          wFulluser)
            return False

        CLS_OSIF.sPrn("mastodonと通信中...")
        #############################
        # mastodonクラス生成
        wCLS_work = CLS_Regist()
        wRes = wCLS_work.CreateMastodon(wFulluser)
        if wRes['Result'] != True:
            CLS_OSIF.sPrn("mastodonと接続できないため中止します。 domain=" +
                          wSTR_user['Domain'])
            return False

        #############################
        # コンソール
        while True:
            #############################
            # コマンド画面表示
            wCommand = self.__manualToot_Disp(wFulluser)

            #############################
            # 継続
            if wCommand == "":
                continue

            #############################
            # 終了
##			elif wCommand=="\q" :
            elif wCommand.find("\\q") >= 0:
                break

            #############################
            # 範囲切り替え
##			elif wCommand=="\c" :
            elif wCommand.find("\\c") >= 0:
                self.SetRange('ManualToot')

            #############################
            # (ないコマンド)
            elif wCommand.find("\\") == 0:
                wStr = "そのコマンドはありません。[RT]"
                CLS_OSIF.sInp(wStr)
                continue

            #############################
            # トゥート
            else:
                wRes = wCLS_work.GetMastodon(wFulluser)
                if wRes['Result'] != True:
                    wStr = "mastodon取得NG: user="******"    " + wRes['Reason']
                    CLS_OSIF.sPrn(wStr)
                    return False

                self.__manualToot(wFulluser, wSTR_user['Domain'], wCommand,
                                  wRes['Responce'])

        return
예제 #23
0
    def SSL_Info(self):
        #############################
        # 監視ユーザのドメインを抜く
        wFulluser = CLS_UserData.sUserCheck(gVal.STR_MasterConfig['AdminUser'])
        if wFulluser['Result'] != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_LookHard: SSL_Info: AdminUser domain is invalid: " +
                gVal.STR_MasterConfig['AdminUser'])
            return False

        #############################
        # 情報取得
        wCertInfo = CLS_SSLCtrl.sGetCertInfo(wFulluser['Domain'])
        ##	"Result"	: False,
        ##	"Reason"	: "",
        ##	"Befour"	: "",		#更新日
        ##	"After"		: "",		#期限日
        ##	"Other"		: {}
        if wCertInfo['Result'] != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_LookHard: SSL_Info: sGetCertInfo is failed: " +
                wCertInfo['Reason'])
            return False

        #############################
        # 期日までの時間差を求める
        wThreshold = 7 * (24 * 60 * 60)  # 7日..意味ないけど
        wLag = CLS_OSIF.sTimeLag(wCertInfo['After'],
                                 inThreshold=wThreshold,
                                 inTimezone=-1)
        ##	"Result"	: False,
        ##	"Beyond"	: False,
        ##	"Future"	: False,
        ##	"InputTime"	: "",
        ##	"NowTime"	: "",
        ##	"RateTime"	: "",
        ##	"RateSec"	: 0
        if wLag['Result'] != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a', "CLS_LookHard: SSL_Info: sTimeLag is failed")
            return False

        #############################
        # 期限切れ通知判定
        wCHR_Body = None
        ##		if wLag['Future']==True and gVal.DEF_STR_TLNUM['indSSLday']>=wLag['RateTime'].days :
        if wLag['Future'] == True and gVal.DEF_STR_TLNUM['indSSLday'] >= wLag[
                'RateDay']:
            ##まだ余裕がある
            ##			wCHR_Body = "サーバ[" + wFulluser['Domain'] + "] のSSL証明書期限切れまであと " + str(wLag['RateTime'].days) + "日です。"
            wCHR_Body = "サーバ[" + wFulluser[
                'Domain'] + "] のSSL証明書期限切れまであと " + str(
                    wLag['RateDay']) + "日です。"
##		else :
##			##期限切れ(てか送信すらできないと思う)
##			wCHR_Body = "サーバ[" + wFulluser['Domain'] + "] のSSL証明書の期限が切れました。"
##
        if wCHR_Body == None:
            return True  #通知日ではない

        #############################
        #トゥートの組み立て
        wCHR_Toot = "@" + gVal.STR_MasterConfig[
            'AdminUser'] + " [SSL証明書期限通知]" + '\n'
        wCHR_Toot = wCHR_Toot + wCHR_Body + '\n'
        ##		wCHR_Toot = wCHR_Toot + "期限日:" + '\n' + wCertInfo['After']
        wCHR_Toot = wCHR_Toot + "期限日:" + '\n' + wCertInfo[
            'After'] + '\n' + "#" + gVal.STR_MasterConfig['SystemTag']

        #############################
        #トゥート
        wRes = self.Obj_Parent.OBJ_MyDon.Toot(status=wCHR_Toot,
                                              visibility="direct")
        if wRes['Result'] != True:
            self.Obj_Parent.OBJ_Mylog.Log(
                'a',
                "CLS_LookHard: SSL_Info: Mastodon error: " + wRes['Reason'])
            return False

        #############################
        # メモ
        self.STR_Info.update({"SSL_Info": {}})
        self.STR_Info['SSL_Info'].update({"UpdateTD": wCertInfo['Befour']})
        self.STR_Info['SSL_Info'].update({"RateTD": wCertInfo['After']})
        ##		self.STR_Info['SSL_Info'].update({ "RateDay"	: str(wLag['RateTime'].days) })
        self.STR_Info['SSL_Info'].update({"RateDay": str(wLag['RateDay'])})

        return True
예제 #24
0
파일: regist.py 프로젝트: xfyer/lucibot
	def Update( self, inFulluser=None ):
		#############################
		# ユーザ名がない場合、名前を入力する
		if inFulluser==None :
			wStr = gVal.STR_SystemInfo['Client_Name'] + " に再登録するユーザ名を入力します。" + '\n'
			wStr = wStr + "再登録するユーザ名をドメインを含めて入力してください。 例= " + gVal.DEF_EXAMPLE_ACCOUNT
			CLS_OSIF.sPrn( wStr )
			inFulluser = CLS_OSIF.sInp( "User?=> " )
		
		#############################
		# ユーザ名の妥当性チェック
		wSTR_user = CLS_UserData.sUserCheck( inFulluser )
		if wSTR_user['Result']!=True :
			CLS_OSIF.sPrn( wSTR_user['Reason'] )
			return False
		elif wSTR_user['Registed']==False :
			CLS_OSIF.sPrn( "そのユーザは登録されていません。: " + inFulluser )
			return False
		
		#############################
		# メールアドレス、パスワードの入力
		wStr = '\n' + inFulluser + " を登録します。"
		wStr = wStr + "mastodonに登録したメールアドレスとパスワードを入力してください。"
		CLS_OSIF.sPrn( wStr )
		
		###入力受け付け
		wMail = CLS_OSIF.sInp( "Mailaddr: " )
		wPass = CLS_OSIF.sGpp( "Password: "******"mastodon ID: " + inFulluser + '\n'
		wStr = wStr + "Mailaddress: " + wMail
		CLS_OSIF.sPrn( wStr )
		wRes = CLS_OSIF.sInp( "以上の内容で登録します(y/N): " )
		if wRes!="y" :
			CLS_OSIF.sPrn( "登録を中止しました" + '\n' )
			return False
		
		#############################
		# 入力チェック
		wRes = self.__registUser( inFulluser, wMail, wPass )
		if wRes['Result']!=True :
			CLS_OSIF.sPrn( wRes['Reason'] )
			return False
		
		CLS_OSIF.sPrn( '\n' + "通信テスト中..." )
		#############################
		# mastodonアクセス前 ping疎通チェック
		if CLS_OSIF.sPing( wSTR_user['Domain'] )!=True :
			CLS_OSIF.sPrn( "mastodonサーバ " + wSTR_user['Domain'] + " が応答しません。登録を中止します。" )
			return False
		
		CLS_OSIF.sPrn( "通信OK" + '\n' + "データ登録中......" )
		#############################
		# レジストファイルの作りなおし
		wGetPath = CLS_UserData.sGetUserPath( inFulluser )
		if wGetPath['Result']!=True :
			CLS_OSIF.sPrn( "CLS_Regist: Update: User path ng: " + wGetPath['Reason'] )
			return False
		
		if CLS_File.sClrFile( wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_RegFile'] )!=True :
			CLS_OSIF.sPrn( "CLS_Regist: Update: Reg File is not found: " + wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_RegFile'] )
			return False
		
		if CLS_File.sClrFile( wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_UserFile'] )!=True :
			CLS_OSIF.sPrn( "CLS_Regist: Update: User File is not found: " + wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_UserFile'] )
			return False
		
		#############################
		# mastodonアカウントへの関連付け(本レジスト)
		wRes = CLS_Regist.sRegistMastodon( inFulluser, wMail, wPass )
		if wRes['Result']!=True :
			wStr = "mastodonへの関連付けに失敗しました" + '\n'
			wStr = wStr + "メールアドレス、パスワード、mastodonが運用中か確認してください。" + '\n'
			wStr = wStr + wRes['Reason']
			CLS_OSIF.sPrn( wStr )
			# データ削除
			CLS_File.sRmtree( wGetPath['Responce'] )
			return False
		
		CLS_OSIF.sPrn( "登録OK" + '\n' + "mastodon登録テスト中......" )
		#############################
		# 通信テスト
		wRes = self.CreateMastodon( inFulluser )
		if wRes['Result']!=True :
			wStr = "mastodonへの関連付けに失敗しました" + '\n'
			wStr = wStr + "メールアドレス、パスワード、mastodonが運用中か確認してください。" + '\n'
			wStr = wStr + wRes['Reason']
			CLS_OSIF.sPrn( wStr )
			# データ削除
			CLS_File.sRmtree( wGetPath['Responce'] )
			return False
		
		CLS_OSIF.sPrn( "mastodon登録OK" + '\n' )
		
		#############################
		# 完了
		CLS_OSIF.sPrn( inFulluser + " の再登録が完了しました" + '\n' )
		return True
예제 #25
0
    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
예제 #26
0
파일: regist.py 프로젝트: xfyer/lucibot
	def Delete( self, inFulluser=None ):
		#############################
		# 1件しかない場合か、MasterUserは削除できない
		#   ※1件しかない場合はそれがMasterUserなので
		wList = CLS_UserData.sGetUserList()
		if len(wList)==1 :
			CLS_OSIF.sPrn( "残り1件しかないので、そのユーザは削除できません。" )
			return False
		
		if gVal.STR_MasterConfig['MasterUser']==inFulluser :
			CLS_OSIF.sPrn( "MasterUserは削除できません。" )
			return False
		
		#############################
		# ユーザ名がない場合、名前を入力する
		if inFulluser==None :
			wStr = gVal.STR_SystemInfo['Client_Name'] + " から削除するユーザ名を入力します。" + '\n'
			wStr = wStr + "削除するユーザ名をドメインを含めて入力してください。 例= " + gVal.DEF_EXAMPLE_ACCOUNT
			CLS_OSIF.sPrn( wStr )
			inFulluser = CLS_OSIF.sInp( "User?=> " )
		
		#############################
		# ユーザ名の妥当性チェック
		wSTR_user = CLS_UserData.sUserCheck( inFulluser )
		if wSTR_user['Result']!=True :
			CLS_OSIF.sPrn( wSTR_user['Reason'] )
			return False
		elif wSTR_user['Registed']==False :
			CLS_OSIF.sPrn( "そのユーザは登録されていません。: " + inFulluser )
			return False
		
		#############################
		# 削除の確認
		CLS_OSIF.sPrn( "ユーザデータの削除をおこないます。データの復旧はできません。" )
		wRes = CLS_OSIF.sInp("本当に削除してよろしいでしょうか(y/N)=> " )
		if wRes!="y" :
			CLS_OSIF.sPrn( "削除を中止しました" + '\n' )
			return False
		
		CLS_OSIF.sPrn( '\n' + "データ削除中......(2分かかります)" )
		#############################
		# cron削除
		wCLS_botjib = CLS_Botjob()
		wDelRes = wCLS_botjib.Del( gVal.DEF_CRON_SUB, inFulluser )
		if wDelRes['Result']==True :
			#############################
			# 実行中のcronが処理が終わるまで待機
			CLS_OSIF.sSleep( 120 )
		else :
##			CLS_OSIF.sPrn( "cronの削除に失敗しました: " + wDelRes['Reason'] )
			CLS_OSIF.sPrn( "cronの削除をスキップします: " + wDelRes['Reason'] )
		
		#############################
		# データ削除
		wGetPath = CLS_UserData.sGetUserPath( inFulluser )
		if wGetPath['Result']!=True :
			CLS_OSIF.sPrn( "CLS_Regist: Delete: User path ng: " + wGetPath['Reason'] )
			return False
		
		if CLS_File.sRmtree( wGetPath['Responce'] )!=True :
			CLS_OSIF.sPrn( "CLS_Regist: Delete: Data is not found: " + wGetPath['Responce'] )
			return False
		
		#############################
		# トラヒックの削除
		wRes = self.__delTrafficUser( inFulluser )
		if wRes['Result']!=True :
			CLS_OSIF.sPrn( "CLS_Regist: Delete: " + wRes['Reason'] )
			return False
		if wRes['Update']==True :
			CLS_OSIF.sPrn( "DBからトラヒック情報が削除されました" )
##		else :
##			CLS_OSIF.sPrn( "トラヒックを計測するユーザが切り替わります" )
		
		#############################
		# 完了
		wStr = inFulluser + " のデータは全て削除されました" + '\n'
		wStr = wStr + "mastodon側の認証済みアプリ情報は手で消してください。" + '\n'
		CLS_OSIF.sPrn( wStr )
		return True
예제 #27
0
	def MasterSetup(self):
		#############################
		# フォルダの存在チェック
		if CLS_File.sExist( gVal.DEF_STR_FILE['MasterConfig_path'] )==True :
			CLS_OSIF.sPrn( "フォルダが既に存在します。セットアップを中止します。" )
			return False	#既にある
		
		wStr = '\n' + "Master環境情報のセットアップを開始します。"
		wStr = wStr + "データのテンプレートをコピーします....."
		CLS_OSIF.sPrn( wStr )
		
		#############################
		# テンプレートデータのコピー(データ作成)
		if CLS_File.sCopytree(
			gVal.DEF_STR_FILE['defMasterdata_path'],
			gVal.DEF_STR_FILE['MasterConfig_path'] )!=True :
			###テンプレートが消えてる (IOエラーはOSが出す)
			CLS_OSIF.sPrn( "CLS_Config: MasterSetup: Master Data Template is not found" )
			return False
		
		#############################
		# フォルダの存在チェック
		if CLS_File.sExist( gVal.DEF_STR_FILE['MasterConfig_path'] )!=True :
			CLS_OSIF.sPrn( "CLS_Config: MasterSetup: Data Copy check failed" )
			return False	#失敗
		
		#############################
		# コピー完了
		CLS_OSIF.sPrn( "Master環境情報のコピーが完了しました。" + '\n' )
		
		#############################
		# 使うクラスの作成
		wCLS_Config = CLS_Config()
		wCLS_Regist = CLS_Regist()
		wCLS_Botjob = CLS_Botjob()
		wCLS_Bot_Ctrl = CLS_Bot_Ctrl()
		
		#############################
		# Master環境情報の変更
		wStr = "Master環境情報の変更をおこないますか?" + '\n'
		wStr = wStr + "(あとで変更することもできます)"
		CLS_OSIF.sPrn( wStr )
		wSelect = CLS_OSIF.sInp( "変更する?(y/N)=> " )
		if wSelect=="y" :
			wRes = wCLS_Config.CnfMasterConfig()
			if wRes!=True :
				##失敗
				CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] )
				return False
		
		#############################
		# 初期起動直後なので、メンテをOFFにする
		# cronを全て剥がす
##		gVal.STR_MasterConfig['mMainte'] = "off"
##		wCLS_Botjob.Stop()
		wCLS_Bot_Ctrl.CronAllStop()
		
		#############################
		# ユーザ登録=0の時、ユーザ登録させる
		wList = CLS_UserData.sGetUserList()
		if len(wList)==0 :
			wFLG_regist = False
			while True:
				wStr = '\n' + "Master User(mastodonでbotとして使うユーザ)の登録をおこないます。" + '\n'
				wStr = wStr + "ユーザ名をドメインを含めて入力してください。: 例= " + gVal.DEF_EXAMPLE_ACCOUNT
				CLS_OSIF.sPrn( wStr )
				wMasterUser = CLS_OSIF.sInp( "MasterUser?=> " )
				wRes = wCLS_Regist.Regist( wMasterUser )
				if wRes==True :
					###登録できたので次へ
					wFLG_regist = True
					break
				else :
					###登録できないと、登録できるまで継続したい
					CLS_OSIF.sPrn( "ユーザの登録がないとbotが動作できません。" )
					wRes = CLS_OSIF.sInp( "登録を中止しますか?(y)=> " )
					if wRes=='y' :
						return False	#セットアップいちお完了だけどユーザ未登録
			
			if wFLG_regist!=True :
				##中止なので消す
				CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] )
				return False
		
		#############################
		# ユーザ登録がされている時
		# もしくは1件だけ登録した時
		# masterユーザを登録する
		wRes = wCLS_Config.CnfMasterUser()
		if wRes!=True :
			##失敗
			CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] )
			return False
		
		#############################
		# AdminUserの変更
		wCLS_Config.CnfAdminUser()
		
##		#############################
##		# MasterとBackgroundのbotを起動する
##		wRes = wCLS_Botjob.Put( gVal.DEF_CRON_MASTER, gVal.STR_MasterConfig['MasterUser'] )
##		if wRes['Result']!=True :
##			wStr = "Master botの起動に失敗しました。: " + wRes['Reason']
##			CLS_OSIF.sPrn( wStr )
##			return False
##		
##		wRes = wCLS_Botjob.Put( gVal.DEF_CRON_BACK, gVal.DEF_CRON_ACCOUNT_BACKGROUND )
##		if wRes['Result']!=True :
##			wStr = "Background botの起動に失敗しました。: " + wRes['Reason']
##			CLS_OSIF.sPrn( wStr )
##			return False
		
		#############################
		# Databaseの作成
		
		#############################
		# DB接続情報ファイルのチェック
		if CLS_File.sExist( gVal.DEF_STR_FILE['DBinfo_File'] )!=True :
##			###DB接続情報ファイルの作成(空ファイル)
##			if CLS_File.sCopy(
##				gVal.STR_File['defDBinfo_File'], gVal.STR_File['DBinfo_File'] )!=True :
##				##失敗
##				CLS_File.sRmtree( gVal.STR_File['MasterConfig_path'] )
##				CLS_File.sRmtree( gVal.DEF_USERDATA_PATH + gVal.STR_MasterConfig['MasterUser'] )
##				
##				wStr = "CLS_Setup: DataBase file copy failed: src=" + gVal.STR_File['defDBinfo_File']
##				wStr = wStr + " dst=" + gVal.STR_File['DBinfo_File']
##				CLS_OSIF.sPrn( wStr  )
##				return False
##			
			wOBJ_DB = CLS_PostgreSQL_Use()
##			if wOBJ_DB.CreateDBdata( gVal.STR_File['DBinfo_File'] )!=True :
			if wOBJ_DB.CreateDBdata( gVal.DEF_STR_FILE['DBinfo_File'], gVal.DEF_STR_FILE['defDBinfo_File'] )!=True :
				##失敗
				CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] )
				CLS_File.sRmtree( gVal.DEF_USERDATA_PATH + gVal.STR_MasterConfig['MasterUser'] )
				
				wStr = "CLS_Setup: DataBase file create failed: src=" + gVal.DEF_STR_FILE['defDBinfo_File']
				wStr = wStr + " dst=" + gVal.DEF_STR_FILE['DBinfo_File']
				CLS_OSIF.sPrn( wStr  )
				return False
##			
##			wOBJ_DB = CLS_PostgreSQL_Use( gVal.DEF_STR_FILE['DBinfo_File'] )
		
		else :
			###DB接続情報変更
			wStr = "DataBaseの接続情報の更新をおこないます。DataBaseの接続情報の更新をおこないますか?"
			print( wStr )
			wSelect = input( "更新する?(y/N)=> " ).strip()
			if wSelect=="y" :
				wOBJ_DB = CLS_PostgreSQL_Use()
##				if wOBJ_DB.CreateDBdata( gVal.DEF_STR_FILE['DBinfo_File'] )!=True :
				if wOBJ_DB.CreateDBdata( gVal.DEF_STR_FILE['DBinfo_File'], gVal.DEF_STR_FILE['defDBinfo_File'] )!=True :
					##失敗
					CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] )
					CLS_File.sRmtree( gVal.DEF_USERDATA_PATH + gVal.STR_MasterConfig['MasterUser'] )
					
					wStr = "CLS_Setup: DataBase file create failed: src=" + gVal.DEF_STR_FILE['defDBinfo_File']
					wStr = wStr + " dst=" + gVal.DEF_STR_FILE['DBinfo_File']
					CLS_OSIF.sPrn( wStr  )
					return False
##				
##				wOBJ_DB = CLS_PostgreSQL_Use( gVal.DEF_STR_FILE['DBinfo_File'] )
		
##		#############################
##		# DBの状態チェック
##		wRes = wOBJ_DB.GetIniStatus()
##		if wRes['Result']!=True :
##			###失敗
##			CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] )
##			CLS_File.sRmtree( gVal.DEF_USERDATA_PATH + gVal.STR_MasterConfig['MasterUser'] )
##			
##			wStr = "CLS_Setup: DB Connect test is failed: " + wRes['Reason']
##			CLS_OSIF.sPrn( wStr  )
##			return False
##		
##		wStr = "テーブルの作成中......" + '\n'
##		print( wStr )
##		#############################
##		# テーブルの作成
##		self.__create_TBL_USER_DATA( wOBJ_DB )
##		self.__create_TBL_TRAFFIC_DATA( wOBJ_DB )
##		self.__create_TBL_WORD_CORRECT( wOBJ_DB )
##		self.__create_TBL_CLAZ_LIST( wOBJ_DB )
##		
##		#############################
##		# DBのクローズ
##		wOBJ_DB.Close()
##		wStr = "作成完了!!  DataBaseから切断しました。" + '\n'
##		print( wStr )
##		
		#############################
		# DBの初期化
		wRes = self.__initDB()
		if wRes!=True :
			###失敗
			CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] )
			CLS_File.sRmtree( gVal.DEF_USERDATA_PATH + gVal.STR_MasterConfig['MasterUser'] )
			
			wStr = "CLS_Setup: DB Connect test is failed: " + wRes['Reason']
			CLS_OSIF.sPrn( wStr  )
			return False
		
		#############################
		# Twitter接続情報の作成
		wOBJ_Twitter = CLS_Twitter_Use()
		wOBJ_Twitter.CreateTwitter( gVal.DEF_STR_FILE['Twitter_File'], gVal.DEF_STR_FILE['defTwitter_File']  )
		wCLS_Config.CnfTwitter()	#有効無効設定
		
		#############################
		# MasterとBackgroundのbotを起動する
		wRes = wCLS_Botjob.Put( gVal.DEF_CRON_MASTER, gVal.STR_MasterConfig['MasterUser'] )
		if wRes['Result']!=True :
			##失敗
			CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] )
			CLS_File.sRmtree( gVal.DEF_USERDATA_PATH + gVal.STR_MasterConfig['MasterUser'] )
			
			wStr = "Master botの起動に失敗しました。: " + wRes['Reason']
			CLS_OSIF.sPrn( wStr )
			return False
		
		return True
예제 #28
0
    def RunAutoFollow(self):
        #############################
        # 開始ログ
        self.Obj_Parent.OBJ_Mylog.Log('b', "自動フォロー 開始")

        wARR_Follower = list(self.ARR_FollowerTL.keys())
        wARR_Follow = list(self.ARR_FollowTL.keys())
        wARR_noFollow = []
        #############################
        # フォローしてない垢を洗い出す
        for wFollower in wARR_Follower:
            if wFollower not in wARR_Follow:
                wARR_noFollow.append(wFollower)

        #############################
        # 除外ドメインを省く
        for wFollower in wARR_noFollow[:]:
            wFulluser = CLS_UserData.sUserCheck(wFollower)
            if wFulluser['Result'] != True:
                ###今のところ通らないルート
                return False

            if wFulluser['Domain'] in gVal.STR_DomainREM:
                wARR_noFollow.remove(wFollower)

        #############################
        # フォローできる条件ならフォローする
        # ・収集されているか
        # ・鍵垢ではない
        # ・30日以内の活動があるか
        for wFollower in wARR_noFollow:
            ### 処理回数の上限チェック
            if self.__check_Follow() != True:
                break

            ### フォローの条件にあてはまるユーザか
            if self.Obj_Parent.OBJ_UserCorr.IsActiveUser(wFollower) != True:
                continue

            ### フォローする
            wID = self.ARR_FollowerTL[wFollower]
            wRes = self.Obj_Parent.OBJ_MyDon.Follow(id=wID)
            if wRes['Result'] != True:
                self.Obj_Parent.OBJ_Mylog.Log(
                    'a', "CLS_Follow: RunAutoFollow: Mastodon error: " +
                    wRes['Reason'])
                return False

            self.VAL_FollowNum += 1
            self.VAL_Followed += 1

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

        #############################
        # 処理結果ログ
        wStr = "自動フォロー 結果: Followed=" + str(
            self.VAL_Followed) + " noFollow=" + str(len(wARR_noFollow))

        if gVal.FLG_Test_Mode == False:
            self.Obj_Parent.OBJ_Mylog.Log('b', wStr)
        else:
            self.Obj_Parent.OBJ_Mylog.Log('b', wStr, True)

        return True
예제 #29
0
    def sRun(cls):
        #############################
        # システム情報を取得する
        cls().__getSystemInfo()
        cls().__getLucibotVer()

        #############################
        # 初期化
        gVal.FLG_Console_Mode = True  #コンソールモード

        #############################
        # データフォルダのチェック
        if CLS_File.sExist(gVal.DEF_USERDATA_PATH) != True:
            ###手順ミスorデータ消した
            wStr = '\n' + gVal.STR_SystemInfo[
                'Client_Name'] + " データフォルダがないため起動できません。" + '\n'
            wStr = wStr + "フォルダは " + gVal.STR_SystemInfo[
                'Client_Name'] + " のcloneを置いた上位フォルダ(=cloneと同一階層)に作成します。" + '\n'
            wStr = wStr + "詳しくはreadme_setup.txtをご参照ください。" + '\n'
            CLS_OSIF.sPrn(wStr)
            return

        #############################
        # Master環境情報の読み込み
        if CLS_Config.sGetMasterConfig() != True:
            # MasterConfigがないのでセットアップするか?
            wStr = '\n' + "データフォルダにMaster環境情報がないため起動できません。" + '\n'
            wStr = wStr + "データが初期セットアップされていない可能性があります。"
            CLS_OSIF.sPrn(wStr)
            wRes = CLS_OSIF.sInp("セットアップしますか?(y/N)=> ")
            if wRes != "y":
                CLS_OSIF.sPrn("起動を中止しました。")
                return

            #############################
            # 環境のセットアップ
            wCLS_Setup = CLS_Setup()
            if wCLS_Setup.MasterSetup() != True:
                CLS_OSIF.sPrn("セットアップを中止します。")
                return

            wCLS_Setup = ""
            CLS_OSIF.sInp('\n' + "セットアップが完了しました。リターンキーを押してください。[RT]")

        #####################################################
        # MasterUserが未登録
        if gVal.STR_MasterConfig['MasterUser'] == "":
            CLS_OSIF.sPrn(
                "MasterUserが登録されていないため、bot動作ができません。MasterUserを登録します。")
            wCLS_Config = CLS_Config()
            wRes = wCLS_Config.CnfMasterUser()
            if wRes != True:
                #############################
                # 0件の場合は、ユーザ登録させる
                wList = CLS_UserData.sGetUserList()
                if len(wList) == 0:
                    wCLS_work = CLS_Regist()
                    wCLS_work.Regist()

                CLS_OSIF.sInp("リターンキーを押して再度コンソールアプリを起動してください。[RT]")
                return

            wCLS_Config = ""

        #############################
        # ** 初期化モード **
        wArg = CLS_OSIF.sGetArg()
        if len(wArg) == 2:
            if wArg[1] == "init":
                wCLS_Setup = CLS_Setup()
                wCLS_Setup.AllInit()
                CLS_OSIF.sInp("リターンキーを押して再度コンソールアプリを起動してください。[RT]")
            return

        #############################
        # コンソールを表示
        while True:
            wCommand = cls().sViewMainConsole()

            if wCommand.find("\\q") >= 0 or wCommand == "exit":
                ###終了
                CLS_OSIF.sPrn("コンソールを停止します。" + '\n')
                break

            wRes = cls().sRunCommand(wCommand)
            if wRes == True:
                CLS_OSIF.sInp("リターンキーを押すと戻ります。[RT]")

        return
예제 #30
0
    def CnfAdminUser(self):
        #############################
        # ファイルの存在チェック
        if CLS_File.sExist(gVal.DEF_STR_FILE['MasterConfig']) != True:
            ###ありえない
            CLS_OSIF.sPrn(
                "CLS_Config: cCnfAdminUser: masterConfig file is not found : "
                + gVal.DEF_STR_FILE['MasterConfig'])
            return False  #ない

        #############################
        # 変更メニュー表示
        if gVal.STR_MasterConfig['AdminUser'] == "":
            wStr = "現在AdminUserは設定されていません。設定することで登録ユーザから通知を受け取ることができるようになります。"
            wSt2 = "AdminUserの設定をおこないますか?(y/N)=> "
        else:
            wStr = "現在AdminUserは次のアカウントが設定されています。: " + gVal.STR_MasterConfig[
                'AdminUser']
            wSt2 = "AdminUserの設定をおこないますか?(y:変更 /D:解除 /other: キャンセル)=> "

        CLS_OSIF.sPrn(wStr)
        wSelect = CLS_OSIF.sInp(wSt2)
        if wSelect == "D":
            ###削除
            gVal.STR_MasterConfig['AdminUser'] = ""
            self.sSetMasterConfig()
            CLS_OSIF.sPrn("AdminUserの設定を解除しました。" + '\n')
            CLS_OSIF.sPrn("設定内容をMaster環境情報にセーブしました: " +
                          gVal.DEF_STR_FILE['MasterConfig'] + '\n')
            return True
        elif wSelect != "y":
            ###設定しない
            CLS_OSIF.sPrn("キャンセルされました")
            return True

        #############################
        # 名前入力
        wStr = "AdminUser(通知先アカウント)をドメインを含めて入力してください。 例= " + gVal.DEF_EXAMPLE_ACCOUNT + '\n'
        wStr = wStr + "  ※ユーザ登録してないユーザも指定できます"
        CLS_OSIF.sPrn(wStr)
        wAdminUser = CLS_OSIF.sInp("AdminUser? => ")
        if wAdminUser=="" or \
           gVal.STR_MasterConfig['AdminUser'] ==wAdminUser :
            ###設定しない
            CLS_OSIF.sPrn("キャンセルされました")
            return True

        #############################
        # ユーザ名の妥当性チェック
        wSTR_user = CLS_UserData.sUserCheck(wAdminUser)
        if wSTR_user['Result'] != True:
            return False

        #############################
        # 通信テスト
        CLS_OSIF.sPrn("通信テスト中...")
        if CLS_OSIF.sPing(wSTR_user['Domain']) != True:
            CLS_OSIF.sPrn("mastodonとの通信テストに失敗したため、設定をキャンセルします。")
            return False

        CLS_OSIF.sPrn("通信OK")

        #############################
        # 変更
        gVal.STR_MasterConfig['AdminUser'] = wAdminUser
        self.sSetMasterConfig()
        CLS_OSIF.sPrn("設定内容をMaster環境情報にセーブしました: " +
                      gVal.DEF_STR_FILE['MasterConfig'] + '\n')
        return True