def action(self): choices = Tools.get_choose_dict( data={"choose": list(self.actions.keys())}) Tools.print_choose_dict(choices) user_input = input() if user_input not in choices.keys(): Tools.print_error("Пожалуйста введите корректные данные.") else: self.context.next(self.actions[choices[user_input]]())
def action(self): choices = Tools.get_choose_dict( data={"choose": list(self.actions.keys())}) Tools.print_choose_dict(choices) user_input = input() if user_input not in choices.keys(): Tools.print_error("Пожалуйста введите корректные данные.") elif choices[user_input] == "Выбрать категорию": go_to = self.handle_download() self.context.next(go_to() if go_to is not None else self. actions[choices[user_input]]()) else: self.context.next(self.actions[choices[user_input]]())
def handle_file_download(self, category): files, choices = self.download_choices(category, "name") file_name_input = input() if choices[file_name_input] in base_actions.keys(): return base_actions[files[file_name_input]] if file_name_input not in choices.keys(): Tools.print_error("Пожалуйста введите корректные данные.") else: file = 0 for d in files: if d["name"] == choices[file_name_input]: file = d self.download_file(category, file) return None
def handle_user_input_download(self, category): values, choices = self.download_choices(category, "name") choice = input() if choices[choice] in base_actions.keys(): return base_actions[values[choice]] if choice not in choices.keys(): Tools.print_error("Пожалуйста введите корректные данные.") else: user_input = {} for d in values: if d["name"] == choices[choice]: user_input = d response = self.context.api.get_data(user_input["id"]) if response.status_code == 200: Tools.print_ok_message("Данные успешно получены.") print(response.text)
def action(self): choices = Tools.get_choose_dict( data={"choose": list(self.actions.keys())}) Tools.print_choose_dict(choices) user_input = input() if user_input not in choices.keys(): Tools.print_error("Пожалуйста введите корректные данные.") elif choices[user_input] == "Начать ввод": raw_data = input() if os.path.isfile(raw_data): files = {"data": open(raw_data, "rb")} self.context.api.create_file(files) else: self.context.api.create_user_input(raw_data) self.context.next(self.actions[choices[user_input]]()) else: self.context.next(self.actions[choices[user_input]]())
def handle_download(self): categories = json.loads(self.context.api.get_categories().text) choices = self.format_to_choose(categories, "name") category_input = input() if category_input not in choices.keys(): Tools.print_error("Пожалуйста введите корректные данные.") elif choices[category_input] in base_actions.keys(): return base_actions[choices[category_input]] else: category = {} is_file = True for d in categories: if d["name"] == choices[category_input]: category = d if d["name"] == "Строки" or d["name"] == "Числа": is_file = False if is_file: return self.handle_file_download(category) else: return self.handle_user_input_download(category) return None