Add resuming

This commit is contained in:
ilikecats 2025-01-01 12:50:47 -08:00
parent bb35a0a198
commit e436ad9aa7

View File

@ -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