def mail(api, ptt_id: str, title: str, content: str, sign_file) -> None: # log.showValue( # api.config, # log.level.INFO, # [ # i18n.PTT, # i18n.Msg # ], # i18n.MarkPost # ) CmdList = [] CmdList.append(command.GoMainMenu) CmdList.append('M') CmdList.append(command.Enter) CmdList.append('S') CmdList.append(command.Enter) CmdList.append(ptt_id) CmdList.append(command.Enter) Cmd = ''.join(CmdList) TargetList = [ connect_core.TargetUnit([i18n.Start, i18n.SendMail], '主題:', break_detect=True), connect_core.TargetUnit(i18n.NoSuchUser, '【電子郵件】', exceptions_=exceptions.NoSuchUser(ptt_id)), ] api.connect_core.send(Cmd, TargetList, screen_timeout=api.config.screen_long_timeout) CmdList = [] CmdList.append(title) CmdList.append(command.Enter) CmdList.append(content) CmdList.append(command.Ctrl_X) Cmd = ''.join(CmdList) if sign_file == 0: SingFileSelection = i18n.NoSignatureFile else: SingFileSelection = i18n.Select + ' ' + \ str(sign_file) + 'th ' + i18n.SignatureFile TargetList = [ connect_core.TargetUnit(i18n.AnyKeyContinue, '任意鍵', break_detect=True), connect_core.TargetUnit( i18n.SaveFile, '確定要儲存檔案嗎', response='s' + command.Enter, # Refresh=False, ), connect_core.TargetUnit(i18n.SelfSaveDraft, '是否自存底稿', response='y' + command.Enter), connect_core.TargetUnit(SingFileSelection, '選擇簽名檔', response=str(sign_file) + command.Enter), connect_core.TargetUnit(SingFileSelection, 'x=隨機', response=str(sign_file) + command.Enter), ] api.connect_core.send(Cmd, TargetList, screen_timeout=api.config.screen_post_timeout) log.show_value(api.config, log.level.INFO, i18n.SendMail, i18n.Success)
def get_user(api, ptt_id: str) -> data_type.UserInfo: cmd_list = list() cmd_list.append(command.GoMainMenu) cmd_list.append('T') cmd_list.append(command.Enter) cmd_list.append('Q') cmd_list.append(command.Enter) cmd_list.append(ptt_id) cmd_list.append(command.Enter) cmd = ''.join(cmd_list) target_list = [ connect_core.TargetUnit( [ i18n.GetUser, i18n.Success, ], screens.Target.AnyKey, break_detect=True), connect_core.TargetUnit( [ i18n.GetUser, i18n.Fail, ], screens.Target.InTalk, break_detect=True), ] index = api.connect_core.send( cmd, target_list) ori_screen = api.connect_core.get_screen_queue()[-1] if index == 1: raise exceptions.NoSuchUser(ptt_id) # PTT1 # 《ID暱稱》CodingMan (專業程式 BUG 製造機)《經濟狀況》小康 ($73866) # 《登入次數》1118 次 (同天內只計一次) 《有效文章》15 篇 (退:0) # 《目前動態》閱讀文章 《私人信箱》最近無新信件 # 《上次上站》10/06/2019 17:29:49 Sun 《上次故鄉》111.251.231.184 # 《 五子棋 》 0 勝 0 敗 0 和 《象棋戰績》 0 勝 0 敗 0 和 # https://github.com/Truth0906/PTTLibrary # 強大的 PTT 函式庫 # 提供您 快速 穩定 完整 的 PTT API # 提供專業的 PTT 機器人諮詢服務 # PTT2 # 《ID暱稱》CodingMan (專業程式 BUG 製造機)《經濟狀況》家徒四壁 ($0) # 《登入次數》8 次 (同天內只計一次) 《有效文章》0 篇 # 《目前動態》看板列表 《私人信箱》最近無新信件 # 《上次上站》10/06/2019 17:27:55 Sun 《上次故鄉》111.251.231.184 # 《 五子棋 》 0 勝 0 敗 0 和 《象棋戰績》 0 勝 0 敗 0 和 # 《個人名片》CodingMan 目前沒有名片 # print(ori_screen) # data = lib_util.get_sub_string_list(ori_screen, '》', ['《', '\n']) data = parse_user_page(ori_screen) if len(data) < 10: print('\n'.join(data)) print(len(data)) raise exceptions.ParseError(ori_screen) # print('\n=> '.join(data)) ptt_id = data[0] money = data[1] login_time = int(data[2]) temp = re.findall(r'\d+', data[3]) legal_post = int(temp[0]) # PTT2 沒有退文 if api.config.host == data_type.host_type.PTT1: illegal_post = int(temp[1]) else: illegal_post = -1 status = data[4] mail = data[5] last_login = data[6] last_ip = data[7] five_chess = data[8] chess = data[9] signature_file = '\n'.join(ori_screen.split('\n')[6:-1]) log.show_value(api.config, log.level.DEBUG, 'ptt_id', ptt_id) log.show_value(api.config, log.level.DEBUG, 'money', money) log.show_value(api.config, log.level.DEBUG, 'login_time', login_time) log.show_value(api.config, log.level.DEBUG, 'legal_post', legal_post) log.show_value(api.config, log.level.DEBUG, 'illegal_post', illegal_post) log.show_value(api.config, log.level.DEBUG, 'status', status) log.show_value(api.config, log.level.DEBUG, 'mail', mail) log.show_value(api.config, log.level.DEBUG, 'last_login', last_login) log.show_value(api.config, log.level.DEBUG, 'last_ip', last_ip) log.show_value(api.config, log.level.DEBUG, 'five_chess', five_chess) log.show_value(api.config, log.level.DEBUG, 'chess', chess) log.show_value(api.config, log.level.DEBUG, 'signature_file', signature_file) user = data_type.UserInfo( ptt_id, money, login_time, legal_post, illegal_post, status, mail, last_login, last_ip, five_chess, chess, signature_file) return user
def mail(api, ptt_id: str, title: str, content: str, sign_file, backup: bool = True) -> None: cmd_list = list() # 回到主選單 cmd_list.append(command.GoMainMenu) # 私人信件區 cmd_list.append('M') cmd_list.append(command.Enter) # 站內寄信 cmd_list.append('S') cmd_list.append(command.Enter) # 輸入 id cmd_list.append(ptt_id) cmd_list.append(command.Enter) cmd = ''.join(cmd_list) # 定義如何根據情況回覆訊息 target_list = [ connect_core.TargetUnit([i18n.Start, i18n.SendMail], '主題:', break_detect=True), connect_core.TargetUnit(i18n.NoSuchUser, '【電子郵件】', exceptions_=exceptions.NoSuchUser(ptt_id)) ] api.connect_core.send(cmd, target_list, screen_timeout=api.config.screen_long_timeout) cmd_list = list() # 輸入標題 cmd_list.append(title) cmd_list.append(command.Enter) # 輸入內容 cmd_list.append(content) # 儲存檔案 cmd_list.append(command.Ctrl_X) cmd = ''.join(cmd_list) # 根據簽名檔調整顯示訊息 if sign_file == 0: sing_file_selection = i18n.NoSignatureFile else: sing_file_selection = i18n.Select + ' ' + \ str(sign_file) + 'th ' + i18n.SignatureFile # 定義如何根據情況回覆訊息 target_list = [ connect_core.TargetUnit(i18n.AnyKeyContinue, '請按任意鍵繼續', break_detect_after_send=True, response=command.Enter), connect_core.TargetUnit( i18n.SaveFile, '確定要儲存檔案嗎', response='s' + command.Enter, ), connect_core.TargetUnit( i18n.SelfSaveDraft if backup else i18n.NotSelfSaveDraft, '是否自存底稿', response=('y' if backup else 'n') + command.Enter), connect_core.TargetUnit(sing_file_selection, '選擇簽名檔', response=str(sign_file) + command.Enter), connect_core.TargetUnit(sing_file_selection, 'x=隨機', response=str(sign_file) + command.Enter), ] # 送出訊息 api.connect_core.send(cmd, target_list, screen_timeout=api.config.screen_post_timeout) log.show_value(api.config, log.level.INFO, i18n.SendMail, i18n.Success)