-
-
Save parzibyte/54e13a12170f492f2225566adefa4dc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import img2pdf | |
""" | |
https://parzibyte.me/blog | |
""" | |
def descargar_imagen(url_base, nombre): | |
url_imagen = f"{url_base}{nombre}.jpg" | |
print(f"Descargando {url_imagen}...") | |
nombre_local_imagen = f"{nombre}.jpg" | |
imagen = requests.get(url_imagen).content | |
print("Guardando...", end="") | |
with open(nombre_local_imagen, 'wb') as handler: | |
handler.write(imagen) | |
print("OK") | |
return nombre_local_imagen | |
def descargar_libro(url_base, paginas, nombre_pdf): | |
inicio = 0 | |
imagenes = [] | |
for i in range(inicio, paginas+1): | |
numero_con_ceros_a_la_izquierda = f"{i:03d}" | |
nombre_imagen_descargada = descargar_imagen( | |
url_base, numero_con_ceros_a_la_izquierda) | |
imagenes.append(nombre_imagen_descargada) | |
with open(nombre_pdf, "wb") as documento: | |
print(f"Guardando imágenes descargadas como {nombre_pdf}") | |
documento.write(img2pdf.convert(imagenes)) | |
descargar_libro( | |
"https://libros.conaliteg.gob.mx/2021/c/P1LEA/", 128, "Español lecturas primer grado.pdf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment