Compare commits
2
Commits
294dd2b04c
...
6981e3fa93
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6981e3fa93 | ||
|
|
2a4a6b9288 |
+21
-7
@@ -91,10 +91,16 @@ if not exists(comic_id):
|
||||
|
||||
while True: # Just going to use `break` to exit
|
||||
print(f"Downloading Comic: {current_comic}")
|
||||
## Get url of image
|
||||
comic_html = bs(requests.get(
|
||||
f"https://www.gocomics.com/{comic_id}/{current_comic}").content,
|
||||
"html.parser")
|
||||
## Get comic url. If status code not 200, retry.
|
||||
comic_url = f"https://www.gocomics.com/{comic_id}/{current_comic}"
|
||||
status = False
|
||||
while status != 200:
|
||||
if status != False:
|
||||
print("Could not get image URL. Retrying...")
|
||||
comic_html = requests.get(comic_url)
|
||||
status = comic_html.status_code
|
||||
comic_html = bs(comic_html.content, "html.parser")
|
||||
## Get image url from comic html
|
||||
image_url = comic_html.find(
|
||||
class_="item-comic-image").contents[0].get("src")
|
||||
## Write image data to file. 'x' means write to new file, 'b' means bin
|
||||
@@ -102,11 +108,19 @@ while True: # Just going to use `break` to exit
|
||||
## '/' with '-'. The := operator both sets a var and evaluates the
|
||||
## condition.
|
||||
if not exists(file := f"{comic_id}/{current_comic.replace('/','-')}.gif"):
|
||||
## Get comic data. If not success, try again.
|
||||
status = False
|
||||
while status != 200:
|
||||
if status != False:
|
||||
print("Could not get image. Retrying...")
|
||||
image = requests.get(image_url)
|
||||
status = image.status_code
|
||||
## Write image to file
|
||||
with open(file, 'xb') as f:
|
||||
f.write(requests.get(image_url).content)
|
||||
f.write(image.content)
|
||||
else:
|
||||
print("{file} exists, delete it to continue.")
|
||||
exit(1)
|
||||
## If file exists, skip
|
||||
print(f"{file} exists, skipping...")
|
||||
## Check if there is a next comic. If there is, choose it for next download.
|
||||
## If there isn't, exit.
|
||||
if not "disabled" in (
|
||||
|
||||
Reference in New Issue
Block a user