From eb1ce5db14d83ec35c12606bee0ef47faaee43d7 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Fri, 16 Sep 2022 02:01:52 +0300 Subject: [PATCH] remove resume feature --- stanis-tits.py | 71 +++----------------------------------------------- 1 file changed, 4 insertions(+), 67 deletions(-) diff --git a/stanis-tits.py b/stanis-tits.py index 75265fd..e0713d7 100755 --- a/stanis-tits.py +++ b/stanis-tits.py @@ -16,55 +16,6 @@ __license__ = "Unlicense" DOWNLOAD_DIRECTORY = "./images" -def resume_load(): - """Возвращает список последних 20 загруженных файлов""" - - # Проверяет наличие файла .resume - if not os.path.exists( - "{0}/.resume".format( - DOWNLOAD_DIRECTORY, - ) - ): - # Создаёт директорию для загрузки сисек - if not os.path.exists(DOWNLOAD_DIRECTORY): - os.mkdir(DOWNLOAD_DIRECTORY) - - # Создаёт файл .resume и пишет в него 0 - with open( - "{0}/.resume".format( - DOWNLOAD_DIRECTORY, - ), - "w", - ) as f: - f.write("0") - return [0] - else: - with open( - "{0}/.resume".format( - DOWNLOAD_DIRECTORY, - ), - "r", - ) as f: - lines = [int(line.split("\n")[0]) for line in f][-20:] - - return lines - - -def resume_save(donwloaded_list): - """Сохраняет список последних 20 загруженных файлов""" - - donwloaded_list.sort() - with open( - "{0}/.resume".format( - DOWNLOAD_DIRECTORY, - ), - "w", - encoding="utf-8", - ) as f: - for item in donwloaded_list[-20:]: - f.write("{0}\n".format(item)) - - def get_images_links(page): """В качестве аргумента получает номер страницы и возвращает списком адреса всех изображений""" @@ -125,23 +76,18 @@ def image_download(image): if __name__ == "__main__": """Главный цикл программы""" - resume_files = resume_load() + if not os.path.exists(DOWNLOAD_DIRECTORY): + os.mkdir(DOWNLOAD_DIRECTORY) current_page = 0 downloaded_counter = 0 - WHILE_BREAK = False - while True: try: # Получаем адреса изображений и сортируем их в порядке возрастания images = get_images_links(current_page) images.sort() - # Костыль - if WHILE_BREAK: - break - # По очереди скачиваем изображения for image in images: # На сайте могут обновляться изображения, @@ -169,17 +115,8 @@ if __name__ == "__main__": # Если в списке resume присутствует текущий загружаемый файл # тогда цикл программы останавливается. # P.S. смотри на костыль WHILE_BREAK - if not int(image.split(".")[0].split("_")[0]) in resume_files: - image_download(image) - resume_files.insert( - 0, - int(image.split(".")[0].split("_")[0]), - ) - downloaded_counter += 1 - resume_save(resume_files) - else: - WHILE_BREAK = True - break + image_download(image) + downloaded_counter += 1 current_page += 1 except KeyboardInterrupt: