def start(): token = common.Cfg().get('wechat', 'token') if not token: token = input('Please enter your wechat token: ') common.Cfg().write('wechat', 'token', token) public_ip = common.Cfg().get('wechat', 'public_ip') if not public_ip: public_ip = input('Please enter public IP: ') common.Cfg().write('wechat', 'public_ip', public_ip) port = common.Cfg().get('wechat', 'port') ma_path = manage.__file__ exe_list = ['python3', ma_path, 'runserver', ':'.join([public_ip, port])] exe_str = ' '.join(exe_list) os.system(exe_str)
def do_check(self, data_path_list=[]): try: if not data_path_list: data_path_list = common.Cfg().get('local', 'data_paths') data_path_list = common.expand_path(data_path_list) data_path_list = common.get_yml_path_list(data_path_list) for data_path in data_path_list: print('') LOG.info('Checking %s' % data_path) with open(data_path, 'r') as f: qas = yaml.load(f.read()) for qa in qas: if not qa: self._error(qa, 'qa is none') for value in qa.values(): if not value: self._error(qa, 'value is none') else: for item in value: if type(item) is dict: self._error(qa, 'item is dict') if not item: self._error(qa, 'item is none') LOG.info('Check Passed!') except Exception as e: LOG.error(e)
def store_idea(self, user, idea_str): if not common.is_super(user): return if not idea_str: return data_path = common.Cfg().get('local', 'data_paths')[0] file_path = os.path.join(data_path, self.store_file) time_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) text = '* %s %s\n' % (time_str, idea_str) with open(file_path, 'a') as fp: fp.write(text) return 'OK, idea is stored.'
def do_teach(self, user, in_str): if not common.is_super(user): return if not in_str: return if self.split_sym not in in_str: return data_path = common.Cfg().get('local', 'data_paths')[0] file_path = os.path.join(data_path, self.teach_file) f = open(file_path, 'a') que = in_str.split(self.split_sym)[0] ans_list = in_str.split(self.split_sym)[1:] ans = self.split_sym.join(ans_list) que = common.init_input(que) ans = common.init_input(ans) text = '\n- que:\n - %s\n ans:\n - %s\n' % (que, ans) f.write(text) f.close() return 'OK, I learned.'
def get_path_list(): path_list = common.Cfg().get('local', 'data_paths') path_list = common.expand_path(path_list) path_list = common.get_md_path_list(path_list) return path_list