Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 25, 2022 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/54e13a12170f492f2225566adefa4dc5 to your computer and use it in GitHub Desktop.
Save parzibyte/54e13a12170f492f2225566adefa4dc5 to your computer and use it in GitHub Desktop.
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