Esempio n. 1
0
 def download_file(self, category, file):
     response = self.context.api.get_data(file["id"])
     if response.status_code == 200:
         path = Path(f"{self.context.storage_path}/{category['name']}/")
         path.mkdir(parents=True, exist_ok=True)
         file_name = f"{path}/{Tools.random_string()}{mimetypes.guess_extension(response.headers['content-type'])}"
         if not os.path.isfile(file_name):
             print(path)
             with open(file_name, "wb+") as destination:
                 for chunk in response:
                     destination.write(chunk)
         Tools.print_ok_message(f"Файл успешно загружен в {file_name}")
Esempio n. 2
0
 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)