mirror of
https://github.com/alanorth/safari-bingo-cards.git
synced 2024-11-27 00:58:20 +01:00
Compare commits
No commits in common. "f3224bee2ea6e59f2d94c22062fd33f7a95378c2" and "b27380e81e345ab0da13bb6369b1fb0c69ce220f" have entirely different histories.
f3224bee2e
...
b27380e81e
22
generate.py
22
generate.py
@ -25,7 +25,7 @@ def create_thumbnail(animal):
|
|||||||
# check if the file has been downloaded
|
# check if the file has been downloaded
|
||||||
if not os.path.isfile(image_path):
|
if not os.path.isfile(image_path):
|
||||||
logger.error(
|
logger.error(
|
||||||
Fore.RED + f"> Missing image for {animal['common_name']}." + Fore.RESET
|
Fore.YELLOW + f"> Missing image for {animal['common_name']}." + Fore.RESET
|
||||||
)
|
)
|
||||||
# check if we already have a thumbnail
|
# check if we already have a thumbnail
|
||||||
elif os.path.isfile(thumbnail_path):
|
elif os.path.isfile(thumbnail_path):
|
||||||
@ -36,6 +36,11 @@ def create_thumbnail(animal):
|
|||||||
+ Fore.RESET
|
+ Fore.RESET
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
logger.info(
|
||||||
|
Fore.GREEN
|
||||||
|
+ f"> Creating thumbnail for {animal['common_name']}..."
|
||||||
|
+ Fore.RESET
|
||||||
|
)
|
||||||
vips_image = pyvips.Image.new_from_file(image_path)
|
vips_image = pyvips.Image.new_from_file(image_path)
|
||||||
# Crop to a 600x600 square using smartcrop to focus attention
|
# Crop to a 600x600 square using smartcrop to focus attention
|
||||||
# See: https://stackoverflow.com/questions/47852390/making-a-huge-image-mosaic-with-pyvips
|
# See: https://stackoverflow.com/questions/47852390/making-a-huge-image-mosaic-with-pyvips
|
||||||
@ -66,13 +71,6 @@ def create_thumbnail(animal):
|
|||||||
# conversion twice.
|
# conversion twice.
|
||||||
vips_thumbnail.vipssave(thumbnail_path, strip=True)
|
vips_thumbnail.vipssave(thumbnail_path, strip=True)
|
||||||
|
|
||||||
logger.info(
|
|
||||||
Fore.GREEN
|
|
||||||
+ f"> Created thumbnail for {animal['common_name']}..."
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@ -89,6 +87,10 @@ def download_image(animal):
|
|||||||
+ Fore.RESET
|
+ Fore.RESET
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
logger.info(
|
||||||
|
Fore.GREEN + f"> Downloading {animal['common_name']}..." + Fore.RESET
|
||||||
|
)
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"User-Agent": "safari-bingo-cards-bot/0.1 (https://git.mjanja.ch/alanorth/safari-bingo-cards)"
|
"User-Agent": "safari-bingo-cards-bot/0.1 (https://git.mjanja.ch/alanorth/safari-bingo-cards)"
|
||||||
}
|
}
|
||||||
@ -97,10 +99,6 @@ def download_image(animal):
|
|||||||
with open(image_path, "wb") as fd:
|
with open(image_path, "wb") as fd:
|
||||||
for chunk in response:
|
for chunk in response:
|
||||||
fd.write(chunk)
|
fd.write(chunk)
|
||||||
|
|
||||||
logger.info(
|
|
||||||
Fore.GREEN + f"> Downloaded {animal['common_name']}..." + Fore.RESET
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
logger.error(
|
logger.error(
|
||||||
Fore.RED
|
Fore.RED
|
||||||
|
Loading…
Reference in New Issue
Block a user