| 83 | self.s.close() |
| 84 | |
| 85 | def itchat_manager(): |
| 86 | def run_and_get(cmd, screen=False): |
| 87 | process = subprocess.Popen( |
| 88 | cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) |
| 89 | output = '' |
| 90 | |
| 91 | for line in process.stdout: |
| 92 | line = line.decode('utf-8') |
| 93 | if screen: |
| 94 | print(line, end='', flush=True) |
| 95 | output += line.strip(' ') |
| 96 | |
| 97 | return output |
| 98 | |
| 99 | @itchat.msg_register(itchat.content.TEXT) |
| 100 | def text_reply(msg): |
| 101 | res_txt = None |
| 102 | cmd_dict = { |
| 103 | 'sq' : 'squeue -p VI_Face_V100', |
| 104 | 'sq1': 'squeue -p VI_Face_1080TI' |
| 105 | } |
| 106 | if msg.text in cmd_dict: |
| 107 | cmd = cmd_dict[msg.text] |
| 108 | res_txt = run_and_get(cmd) |
| 109 | elif msg.text.startswith('exec:'): |
| 110 | cmd = msg.text.replace('exec:', '') |
| 111 | if os.system(cmd) == 0: |
| 112 | res_txt = 'exec successed!' |
| 113 | else: |
| 114 | res_txt = 'exec failed!' |
| 115 | elif msg.text.startswith('getinfo:'): |
| 116 | cmd = msg.text.replace('getinfo:', '') |
| 117 | res_txt = run_and_get(cmd) |
| 118 | |
| 119 | if res_txt is not None: |
| 120 | itchat.send(res_txt, toUserName='filehelper') |
| 121 | |
| 122 | itchat.auto_login(enableCmdQR=2, hotReload=True) |
| 123 | itchat.run(True) |
| 124 | |
| 125 | if __name__ == '__main__': |
| 126 | args = parser.parse_args() |