From e436ad9aa7baa9276f808fa6fe3064ab972a238c Mon Sep 17 00:00:00 2001 From: ilikecats Date: Wed, 1 Jan 2025 12:50:47 -0800 Subject: [PATCH] Add resuming --- downloader.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/downloader.py b/downloader.py index bcab11d..6bace2e 100755 --- a/downloader.py +++ b/downloader.py @@ -16,13 +16,10 @@ this program. If not, see https://www.gnu.org/licenses/ """ -### TODO -## Fast resume (resume from last downloaded comic) - import requests from bs4 import BeautifulSoup as bs -from os import mkdir -from os.path import exists +from os import mkdir, listdir +from os.path import exists, isfile from sys import argv ### Copyleft message @@ -84,16 +81,28 @@ current_comic = first_comic print(f"Start date: {first_comic}") -### Make directory to store comics in +### If directory exists, check for files and get resume date from most recently +### labled one +resuming = False if not exists(comic_id): mkdir(comic_id) +else: ## Dir exists + ## Make sure there are files + ## This means "Get the list of files in the `comic_id` folder and sort them. + ## Set `listing` to them." + if (listing := sorted( + [x for x in listdir(comic_id) if isfile(f"{comic_id}/{x}")])) != []: + ## Start from most recent lable (remove .gif and replace - with /) + current_comic = listing[-1][0:-4].replace('-','/') ### Starting from the first comic, download all the comics until the "next" ### button is greyed out. +print(f"Downloading from: {current_comic}") + while True: # Just going to use `break` to exit - print(f"Downloading Comic: {current_comic}") + print(f"Downloading comic: {current_comic}") ## Get comic url. If status code not 200, retry. comic_url = f"https://www.gocomics.com/{comic_id}/{current_comic}" status = False