예제 #1
0
파일: dbedit.py 프로젝트: xfyer/lucibot
    def __getMstdnDomains(self):
        #############################
        # mastodonからドメイン情報を取得
        wQuery = "select distinct domain from accounts;"

        wRes = self.__oneRunQueryMstdn(wQuery)
        if wRes['Result'] != True:
            ##失敗
            CLS_OSIF.sInp("リターンキーを押すと戻ります。[RT]")
            return

        #############################
        # ファイルに取得
        self.ARR_Domains = []
        for wLineTap in wRes['Responce']['Data']:
            for wCel in wLineTap:
                wCel = str(wCel)
                wCel = wCel.strip()
                self.ARR_Domains.append(wCel)
        self.__setDomainsFile()

        #############################
        # 件数表示
        wStr = str(len(self.ARR_Domains)) + " 件取得しました" + '\n'
        CLS_OSIF.sPrn(wStr)
        CLS_OSIF.sInp('\n' + "リターンキーを押すと戻ります。[RT]")
        return
예제 #2
0
파일: toot.py 프로젝트: xfyer/lucibot
    def __manualToot(self, inFulluser, inDomain, inToot, inMastodon):
        #############################
        # 分かるよう加工
        wTag = '\n' + gVal.STR_MasterConfig['mTootTag'] + " @" + inFulluser
        wToot = inToot + wTag

        wMaxToot = 500 - len(wTag)
        if len(wToot) > 500:
            wRes = CLS_OSIF.sInp(str(wMaxToot) + " 文字以上は送信できません。[RT]")
            return False

        CLS_OSIF.sPrn("mastodonに送信中...")
        #############################
        # IP疎通チェック
        if CLS_OSIF.sPing(inDomain) != True:
            wRes = CLS_OSIF.sInp("mastodonと接続できないため送信できませんでした。[RT]")
            return False

        #############################
        #トゥート
        wRes = inMastodon.Toot(status=wToot,
                               visibility=self.STR_TootRange['ManualToot'])
        if wRes['Result'] != True:
            CLS_OSIF.sPrn("mastodon API Error: " + wRes['Reason'])
            wRes = CLS_OSIF.sInp("継続します。[RT]")
            return False

        wRes = CLS_OSIF.sInp("トゥートの送信を正常におこないました。[RT]")
        return True
예제 #3
0
파일: toot.py 프로젝트: xfyer/lucibot
    def __getTwitterTL(self, inTwitter):
        CLS_OSIF.sPrn("タイムラインの取得中..." + '\n')
        #############################
        # 取得
        ##		wRes = inTwitter.GetTL( inTLmode="user", inList=None, inReply=True, inRetweet=False )
        ##		wRes = inTwitter.GetTL( inTLmode="home", inList=None, inReply=True, inRetweet=True )
        ##		wRes = inTwitter.GetTL( inTLmode="list", inList=1006036956923363328, inReply=True, inRetweet=False )
        ##		wRes = inTwitter.GetTL( inTLmode="list", inList=1164128983975206912, inReply=True, inRetweet=False )
        wRes = inTwitter.GetTL()
        if wRes['Result'] != True:
            CLS_OSIF.sPrn("Twitter API Error: " + wRes['Reason'])
            wRes = CLS_OSIF.sInp("継続します。[RT]")
            return False

        #############################
        # 画面に表示
        for wROW in wRes['Responce']:
            CLS_OSIF.sPrn("Country: " + str(wROW['lang']))
            if "possibly_sensitive" not in wROW:
                CLS_OSIF.sPrn("Sensitive: ON")
            CLS_OSIF.sPrn("Locked: " + str(wROW['user']['protected']))
            CLS_OSIF.sPrn("Sender: " + wROW['user']['name'] + "(@" +
                          wROW['user']['screen_name'] + ")")

            CLS_OSIF.sPrn(wROW['text'])
            CLS_OSIF.sPrn(
                "------------------------------------------------------------")

        #############################
        # 正常
        wRes = CLS_OSIF.sInp("タイムラインの取得を正常におこないました。[RT]")
        return True
예제 #4
0
파일: dbedit.py 프로젝트: xfyer/lucibot
    def __searchMstdnDomainBlock(self):
        #############################
        # ドメイン情報 読み込み
        self.__getDomainsFile()
        if len(self.ARR_Domains) == 0:
            ##失敗
            CLS_OSIF.sInp("まず mlでドメインを取得してください。[RT]")
            return

        #############################
        # サーチするコメントを指定
        wStr = "ドメインブロックサーチするコメント(公開)を入力してください" + '\n'
        CLS_OSIF.sPrn(wStr)
        wInput = CLS_OSIF.sInp("コメント?=> ")
        if wInput == "":
            return

        #############################
        # mastodonからドメインブロックを取得
##		wQuery = "select domain from domain_blocks where public_comment = '\%" + str(wInput) + "\%';"
##		wQuery = "select domain from domain_blocks where public_comment like '%" + str(wInput) + "%';"
        wQuery = "select domain from domain_blocks where public_comment like '%" + str(
            wInput) + "%' order by domain;"

        CLS_OSIF.sPrn(wQuery)

        wRes = self.__oneRunQueryMstdn(wQuery)
        if wRes['Result'] != True:
            ##失敗
            CLS_OSIF.sInp("リターンキーを押すと戻ります。[RT]")
            return

        ##対象なし
        if len(wRes['Responce']['Data']) == 0:
            wStr = "対象ドメインはありません。" + '\n'
            CLS_OSIF.sPrn(wStr)
            CLS_OSIF.sInp('\n' + "リターンキーを押すと戻ります。[RT]")
            return

        #############################
        # ドメインの表示
        wStr = "-----------------------" + '\n'
        wStr = wStr + "検知したドメイン" + '\n'
        wStr = wStr + "-----------------------" + '\n'
        for wLineTap in wRes['Responce']['Data']:
            for wCel in wLineTap:
                wCel = str(wCel)
                wCel = wCel.strip()
            wStr = wStr + wCel + '\n'

        CLS_OSIF.sPrn(wStr)
        CLS_OSIF.sInp('\n' + "リターンキーを押すと戻ります。[RT]")
        return
예제 #5
0
파일: toot.py 프로젝트: xfyer/lucibot
    def SetRange(self, inKind):
        if inKind not in self.STR_TootRange:
            ###ロジックエラー
            ###			global_val.gCLS_Init.cPrint( "CLS_Toot: SetRange: STR_TootRange not in key: " + inKind )
            CLS_OSIF.sPrn("CLS_Toot: SetRange: STR_TootRange not in key: " +
                          inKind)
            return

        #############################
        # 切替メニュー
        if inKind == "ManualToot":
            wStr = '\n' + "範囲切替= p:public(公開) / u:unlisted(未収載) / l:private(非公開) / d:direct(DM)"
        else:
            ## Multicast
            wStr = '\n' + "範囲切替= p:public(公開) / u:unlisted(未収載)"

        CLS_OSIF.sPrn(wStr)
        wRes = CLS_OSIF.sInp("切替?=> ")

        #############################
        # 範囲切替 設定
        if wRes == "p":
            self.STR_TootRange[inKind] = "public"
        elif wRes == "u":
            self.STR_TootRange[inKind] = "unlisted"
##		elif wRes=="l" :
        elif wRes == "l" and inKind == "ManualToot":
            self.STR_TootRange[inKind] = "private"
        elif wRes == "d" and inKind == "ManualToot":
            self.STR_TootRange[inKind] = "direct"

        return
예제 #6
0
파일: toot.py 프로젝트: xfyer/lucibot
    def __multicastList(self, inSendlist):
        wStr = '\n' + "配信先一覧" + '\n'
        wKeylist = inSendlist.keys()
        for iKey in wKeylist:
            wStr = wStr + iKey + '\n'

        CLS_OSIF.sPrn(wStr)
        wCommand = CLS_OSIF.sInp("同報配信先を出力しました。[RT]")
        return
예제 #7
0
파일: toot.py 프로젝트: xfyer/lucibot
    def __manualTweet(self, inTwitter, inTweet):
        #############################
        # 文字数チェック
        wMaxToot = 140 - len(inTweet)
        if len(inTweet) > 140:
            wRes = CLS_OSIF.sInp(str(wMaxToot) + " 文字以上は送信できません。[RT]")
            return False

        CLS_OSIF.sPrn("Twitterに送信中...")
        #############################
        #ついーと
        wRes = inTwitter.Tweet(inTweet)
        if wRes['Result'] != True:
            CLS_OSIF.sPrn("Twitter API Error: " + wRes['Reason'])
            wRes = CLS_OSIF.sInp("継続します。[RT]")
            return False

        wRes = CLS_OSIF.sInp("ツイートの送信を正常におこないました。[RT]")
        return True
예제 #8
0
    def sViewMainConsole(cls):

        #############################
        # メインコンソール画面
        wRes = cls().sViewDisp("MainConsole")
        if wRes == False:
            return "q"  #失敗=強制終了

        wCommand = CLS_OSIF.sInp("コマンド?=> ")
        return wCommand
예제 #9
0
파일: toot.py 프로젝트: xfyer/lucibot
    def __multicastToot(self, inFulluser, inSendlist, inToot, inSTR_Mastodon):
        #############################
        # 分かるよう加工
        wTtl = "[Multicast] "
        wTag = '\n' + gVal.STR_MasterConfig['mTootTag'] + " @" + inFulluser
        wToot = wTtl + inToot + wTag

        wMaxToot = 500 - (len(wTtl) + len(wTag))
        if len(wToot) > 500:
            wRes = CLS_OSIF.sInp(str(wMaxToot) + " 文字以上は送信できません。[RT]")
            return False

        CLS_OSIF.sPrn("mastodonに配信中...")
        wKeylist = inSendlist.keys()
        wListLen = len(wKeylist)
        wSend = 0
        for iKey in wKeylist:
            #############################
            # mastodonオブジェクト取得
            wMastodon = inSTR_Mastodon.GetMastodon(iKey)
            if wMastodon['Result'] != True:
                wStr = "mastodon取得NG: user="******"    " + wMastodon['Reason']
                CLS_OSIF.sPrn(wStr)
                continue

            #############################
            # IP疎通チェック
            if CLS_OSIF.sPing(inSendlist[iKey]['domain']) != True:
                CLS_OSIF.sPrn("通信NG: " + inSendlist[iKey]['domain'])
                continue

            #############################
            #トゥート
            wRes = wMastodon['Responce'].Toot(
                status=wToot, visibility=self.STR_TootRange['Multicast'])
            if wRes['Result'] != True:
                CLS_OSIF.sPrn("mastodon API Error: " + wRes['Reason'] +
                              ": account= " + iKey)
                continue

            CLS_OSIF.sPrn("送信OK: " + inSendlist[iKey]['domain'])

            #############################
            #カウント
            wSend += 1
            if wListLen > wSend:
                ###送り切ってなければディレイする
                CLS_OSIF.sSleep(gVal.DEF_STR_TLNUM['getMcDelay'])

        wRes = CLS_OSIF.sPrn("配信完了。[RT]")
        return True
예제 #10
0
파일: bot_ctrl.py 프로젝트: xfyer/lucibot
    def __allRun(self):
        #############################
        # フラグの確認
        if self.FLG_On == True:
            ###ありえない
            wStr = "CLS_Bot_Ctrl: __allStop: __allRun flag contradiction" + '\n'
            wStr = wStr + "フラグをリセットしました。再度やり直してください。[RT]"
            CLS_OSIF.sInp(wStr)
            self.FLG_On = False
            return

        #############################
        # 起動中のbotがあるか
        # あれば停止していく
        wKeylist = self.UserList.keys()
        for wUser in wKeylist:
            #############################
            # 種別の設定
            wKind = self.__getKind(wUser)

            #############################
            # ジョブの登録
            wRes = self.OBJ_Job.Put(wKind, wUser)
            if wRes['Result'] != True:
                ###失敗
                wStr = "cronの登録が失敗しました。 User:"******" Reason: " + wRes[
                    'Reason']
                CLS_OSIF.sPrn(wStr)
                continue

        self.WaitRestart = []

        #############################
        # 処理結果
        wStr = "全botを起動しました。[RT]"
        CLS_OSIF.sInp(wStr)
        self.FLG_AllStop = False
        return
예제 #11
0
파일: dbedit.py 프로젝트: xfyer/lucibot
    def __View_Disp(self):
        #############################
        # 画面クリア
        CLS_OSIF.sDispClr()

        #############################
        # ヘッダ出力
        wStr = "-----------------------" + '\n'
        wStr = wStr + " データベース エディタ" + '\n'
        wStr = wStr + "-----------------------" + '\n'
        ##		wStr = wStr + "DB Name: " + self.STR_DBdata['database'] + '\n'
        wStr = wStr + "コマンド= [\\q] 終了 / [\\l] 一覧"
        CLS_OSIF.sPrn(wStr)
        wCommand = CLS_OSIF.sInp("コマンド?=> ").strip()
        return wCommand
예제 #12
0
파일: bot_ctrl.py 프로젝트: xfyer/lucibot
    def __reStart(self):
        #############################
        # コマンド受かったので一回フラグを落とす
        self.FLG_AllStop = False

        #############################
        # 再開待ちリストで再開中のユーザを起動していく
        wFLG_Start = False
        for wUser in self.WaitRestart:
            #############################
            # 種別の設定
            wKind = self.__getKind(wUser)

            #############################
            # ジョブの作成
            wRes = self.OBJ_Job.Put(wKind, wUser)
            if wRes['Result'] != True:
                ###失敗
                wStr = "cronの作成が失敗しました。 User:"******" Reason: " + wRes[
                    'Reason']
                CLS_OSIF.sPrn(wStr)
                continue

            wFLG_Start = True

        #############################
        # 処理結果
        if wFLG_Start == False:
            ###ジョブ作成失敗以外はありえない
            wStr = "起動したbotはありませんでした。[RT]"
            CLS_OSIF.sInp(wStr)
            return

        wStr = "起動中だったbotを再開しました。[RT]"
        CLS_OSIF.sInp(wStr)
        return
예제 #13
0
파일: toot.py 프로젝트: xfyer/lucibot
    def __manualToot_Disp(self, inFulluser):
        #############################
        # 画面クリア
        CLS_OSIF.sDispClr()

        #############################
        # ヘッダ出力
        wStr = "--------------------" + '\n'
        wStr = wStr + " 手動トゥートモード" + '\n'
        wStr = wStr + "--------------------" + '\n'
        wStr = wStr + "アカウント: " + inFulluser + '\n'
        wStr = wStr + "公開モード: " + self.STR_TootRange['ManualToot'] + '\n' + '\n'
        wStr = wStr + "コマンド= [\\q] 終了 / [\\c] 範囲切替 / [other] トゥート!!"
        CLS_OSIF.sPrn(wStr)
        wCommand = CLS_OSIF.sInp("コマンド?=> ")
        return wCommand
예제 #14
0
파일: toot.py 프로젝트: xfyer/lucibot
    def __multicastToot_Disp(self, inFulluser, inNum):
        #############################
        # 画面クリア
        CLS_OSIF.sDispClr()

        #############################
        # ヘッダ出力
        wStr = "--------------------" + '\n'
        wStr = wStr + " 同報配信トゥートモード" + '\n'
        wStr = wStr + "--------------------" + '\n'
        wStr = wStr + "Masterアカウント: " + inFulluser + '\n'
        wStr = wStr + "同報配信先数    : " + str(inNum) + '\n'
        wStr = wStr + "公開モード: " + self.STR_TootRange['Multicast'] + '\n' + '\n'
        wStr = wStr + "コマンド= [\\q] 終了 / [\\c] 範囲切替 / [\\l] 配信先一覧 / [other] トゥート!!"
        CLS_OSIF.sPrn(wStr)
        wCommand = CLS_OSIF.sInp("コマンド?=> ")
        return wCommand
예제 #15
0
파일: bot_ctrl.py 프로젝트: xfyer/lucibot
    def __start(self):
        #############################
        # 全停止の場合は、再開処理にする
        #  =再開コマンド
        if self.FLG_AllStop == True:
            self.__reStart()
            return

        #############################
        # ユーザ名の入力
        wStr = "bot起動するユーザ名をドメインを含める形で入力してください。"
        CLS_OSIF.sPrn(wStr)
        wUser = CLS_OSIF.sInp("User?=> ")

        #############################
        # ユーザ名の確認
        wKeylist = self.UserList.keys()
        if wUser not in wKeylist:
            wStr = "登録のないユーザです。[RT]"
            CLS_OSIF.sInp(wStr)
            return

        if self.UserList[wUser] == True:
            wStr = "既に起動してます。[RT]"
            CLS_OSIF.sInp(wStr)
            return

        #############################
        # 種別の設定
        wKind = self.__getKind(wUser)

        #############################
        # ジョブの作成
        wRes = self.OBJ_Job.Put(wKind, wUser)

        #############################
        # 結果
        if wRes['Result'] == True:
            ###成功
            wStr = "cronに登録成功しました。"
            CLS_OSIF.sPrn(wStr)
        else:
            ###失敗
            wStr = "cronへの登録が失敗しました。 Reason: " + wRes['Reason']
            CLS_OSIF.sPrn(wStr)

        CLS_OSIF.sInp("確認したらリターンキーを押してください。[RT]")
        return
예제 #16
0
파일: bot_ctrl.py 프로젝트: xfyer/lucibot
    def __stop(self):
        #############################
        # ユーザ名の入力
        wStr = "bot停止するユーザ名をドメインを含める形で入力してください。"
        CLS_OSIF.sPrn(wStr)
        wUser = CLS_OSIF.sInp("User?=> ")

        #############################
        # ユーザ名の確認
        wKeylist = self.UserList.keys()
        if wUser not in wKeylist:
            wStr = "登録のないユーザです。[RT]"
            CLS_OSIF.sInp(wStr)
            return

        if self.UserList[wUser] == False:
            wStr = "既に停止してます。[RT]"
            CLS_OSIF.sInp(wStr)
            return

        #############################
        # 種別の設定
        wKind = self.__getKind(wUser)

        #############################
        # ジョブの削除
        wRes = self.OBJ_Job.Del(wKind, wUser)

        #############################
        # 結果
        if wRes['Result'] == True:
            ###成功
            wStr = "cronを削除しました。2分以内にはbotが止まります。"
            CLS_OSIF.sPrn(wStr)
        else:
            ###失敗
            wStr = "cronの削除が失敗しました。 Reason: " + wRes['Reason']
            CLS_OSIF.sPrn(wStr)

        CLS_OSIF.sInp("確認したらリターンキーを押してください。[RT]")
        return
예제 #17
0
파일: bot_ctrl.py 프로젝트: xfyer/lucibot
    def __allStop(self):
        #############################
        # フラグの確認
        if self.FLG_AllStop == True:
            ###ありえない
            wStr = "CLS_Bot_Ctrl: __allStop: FLG_AllStop flag contradiction" + '\n'
            wStr = wStr + "フラグをリセットしました。再度やり直してください。[RT]"
            CLS_OSIF.sInp(wStr)
            self.FLG_AllStop = False
            return False

        #############################
        # 起動中のbotがあるか
        # あれば停止していく
        self.WaitRestart = []
        wKeylist = self.UserList.keys()
        for wUser in wKeylist:
            if self.UserList[wUser] == True:
                #############################
                # 種別の設定
                wKind = self.__getKind(wUser)

                #############################
                # ジョブの削除
                wRes = self.OBJ_Job.Del(wKind, wUser)
                if wRes['Result'] != True:
                    ###失敗
                    wStr = "cronの削除が失敗しました。 User:"******" Reason: " + wRes[
                        'Reason']
                    CLS_OSIF.sPrn(wStr)
                    continue

                self.WaitRestart.append(wUser)

        #############################
        # 処理結果
        if len(self.WaitRestart) == 0:
            wStr = "停止したbotはありませんでした。[RT]"
            CLS_OSIF.sInp(wStr)
            return False

        wStr = "起動中のbotを停止しました。[RT]"
        CLS_OSIF.sInp(wStr)
        self.FLG_AllStop = True
        return True
예제 #18
0
파일: toot.py 프로젝트: xfyer/lucibot
    def __ManualTweet_Disp(self, inTwitter):
        #############################
        # 画面クリア
        CLS_OSIF.sDispClr()

        #############################
        # ヘッダ出力
        wStr = "--------------------" + '\n'
        wStr = wStr + " 手動ついーとモード" + '\n'
        wStr = wStr + "--------------------" + '\n'
        wStr = wStr + "アカウント: " + inTwitter.GetUsername() + '\n'
        wStr = wStr + "Mode   : " + inTwitter.STR_TWITTERdata['Mode']
        if inTwitter.STR_TWITTERdata['Mode'] == "list":
            wStr = wStr + " / ListID= " + str(
                inTwitter.STR_TWITTERdata['List'])
        wStr = wStr + '\n'
        wStr = wStr + "NoReply: " + inTwitter.STR_TWITTERdata['NoReply'] + '\n'
        wStr = wStr + "Retweet: " + inTwitter.STR_TWITTERdata['Retweet'] + '\n'
        ##		wStr = wStr + "コマンド= [\\q] 終了 / [\\g] TL取得 / [\\l] List取得 / [other] ついーと!!"
        wStr = wStr + "コマンド= [\\q] 終了 / [\\g] TL取得 / [other] ついーと!!"
        CLS_OSIF.sPrn(wStr)
        wCommand = CLS_OSIF.sInp("コマンド?=> ")
        return wCommand
예제 #19
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
예제 #20
0
파일: dbedit.py 프로젝트: xfyer/lucibot
    def __checkMstdnNewDomains(self):
        #############################
        # ドメイン情報 読み込み
        self.__getDomainsFile()
        if len(self.ARR_Domains) == 0:
            ##失敗
            CLS_OSIF.sInp("まず mlでドメインを取得してください。[RT]")
            return

        #############################
        # mastodonからドメイン情報を取得
        wQuery = "select distinct domain from accounts;"

        wRes = self.__oneRunQueryMstdn(wQuery)
        if wRes['Result'] != True:
            ##失敗
            CLS_OSIF.sInp("リターンキーを押すと戻ります。[RT]")
            return

        #############################
        # 新ドメインだけ抜きとる
        wNewDomains = []
        for wLineTap in wRes['Responce']['Data']:
            for wCel in wLineTap:
                wCel = str(wCel)
                wCel = wCel.strip()
            if wCel not in self.ARR_Domains:
                wNewDomains.append(wCel)

        #############################
        # 新ドメインの表示
        if len(wNewDomains) > 0:
            wStr = "-----------------------" + '\n'
            wStr = wStr + "新しく検知したドメイン" + '\n'
            wStr = wStr + "-----------------------" + '\n'
            for wLine in wNewDomains:
                wStr = wStr + wLine + '\n'
            CLS_OSIF.sPrn(wStr)
        else:
            wStr = "新しく検知したドメインはありません。" + '\n'
            CLS_OSIF.sPrn(wStr)

        CLS_OSIF.sInp('\n' + "リターンキーを押すと戻ります。[RT]")
        return
예제 #21
0
파일: dbedit.py 프로젝트: xfyer/lucibot
    def __viewTblList(self):
        #############################
        # 一覧の取得
        ##		wQuery = "select tablename from pg_tables where tablename not like 'pg_%' and schemaname like 'public';"
        ##		wQuery = "select t2.relname , t2.reltuples from pg_stat_user_tables as t1 inner join pg_class as t2 on t1.relname = t2.relname order by t2.relname;"
        wQuery = "select relname, n_live_tup from pg_stat_user_tables where schemaname='public';"

        wRes = self.__oneRunQuery(wQuery)
        if wRes['Result'] != True:
            ##失敗
            CLS_OSIF.sInp("リターンキーを押すと戻ります。[RT]")
            return

        if len(wRes['Responce']['Data']) == 0:
            ##滅多にありえない
            CLS_OSIF.sInp("データベースが初期化されていません。[RT]")
            return

        #############################
        # ヘッダ出力
        wStr = "-----------------------" + '\n'
        wStr = wStr + "レコード数   テーブル名" + '\n'
        wStr = wStr + "-----------------------"
        CLS_OSIF.sPrn(wStr)
        ###		print( str(wRes['Responce']['Data']) )

        ##データの表示
        for wLineTap in wRes['Responce']['Data']:
            wGetTap = []
            for wCel in wLineTap:
                wCel = str(wCel)
                wCel = wCel.strip()
                wGetTap.append(wCel)
                ## [0]..テーブル名
                ## [1]..レコード数
            wStr = wGetTap[1] + (" " * (13 - len(wGetTap[1]))) + wGetTap[0]
            CLS_OSIF.sPrn(wStr)

        #############################
        CLS_OSIF.sInp('\n' + "リターンキーを押すと戻ります。[RT]")
        return
예제 #22
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
예제 #23
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
예제 #24
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
예제 #25
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
예제 #26
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
예제 #27
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
예제 #28
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
예제 #29
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
예제 #30
0
파일: bot_ctrl.py 프로젝트: xfyer/lucibot
    def __consoleViewList(self):
        #############################
        # List取得
        wRes = self.OBJ_Job.GetList()
        if wRes['Result'] != True:
            return False
        ## wRes['Responce']['List']:

        #############################
        # ヘッダ
        wStr = "--------------------" + '\n'
        wStr = wStr + " bot一覧 (crontab)" + '\n'
        wStr = wStr + "--------------------" + '\n'

        #############################
        # 内容
        #   crontabにユーザが登録されていれば *ON
        #   crontabにユーザが未登録なら        OFF
        self.FLG_On = False
        wKeylist = self.UserList.keys()
        for wUser in wKeylist:
            wFlg_Online = False
            for wJob in wRes['Responce']['List']:
                if wJob.find(wUser) >= 0:
                    wFlg_Online = True

            if wFlg_Online == True:
                self.UserList[wUser] = True
                wStat = "*ON "
                self.FLG_On = True
            else:
                self.UserList[wUser] = False
                wStat = " OFF"

            wStr = wStr + "    " + wStat + "    " + wUser + '\n'

        #############################
        # コマンド見本
##		if self.FLG_AllStop==False :
##			wStr = wStr + "コマンド= [\\q] 終了 / [\\r] 起動 / [\\s] 停止 / [\\as] 全停止" + '\n'
##		else:
##			wStr = wStr + "コマンド= [\\q] 終了 / [\\r] 再開" + '\n'
        if self.FLG_On == True:
            if self.FLG_AllStop == False:
                wStr = wStr + "コマンド= [\\q] 終了 / [\\r] 起動 / [\\s] 停止 / [\\as] 全停止" + '\n'
            else:
                wStr = wStr + "コマンド= [\\q] 終了 / [\\r] 再開" + '\n'

        else:
            ###どこも起動してない場合
            wStr = wStr + "コマンド= [\\q] 終了 / [\\r] 再開 / [\\ar] 全起動" + '\n'

        #############################
        # 出力
        CLS_OSIF.sDispClr()
        CLS_OSIF.sPrn(wStr)

        #############################
        # コマンド
        wCommand = CLS_OSIF.sInp("コマンド?=> ")
        return wCommand