Last active
March 23, 2020 05:46
-
-
Save user0able/ad0fefa5575de4a0d80cd00e4a633f5a 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 datetime | |
import requests | |
import img2pdf | |
from os import remove | |
hoy = datetime.datetime.now().date() | |
def getFecha(): | |
today = datetime.date.today() | |
oneday = datetime.timedelta(days=1) | |
yesterday = today - oneday | |
return yesterday | |
def genera_web_base(fecha=getFecha()): | |
web_base = 'https://impresa.soy-chile.cl/AustralValdivia/%s%s%s/AustralValdivia/%s_%s_%s_pag_' % ( | |
(fecha.day if fecha.day >= 10 else '0' + fecha.day.__str__()), | |
fecha.month if fecha.month >= 10 else '0' + fecha.month.__str__(), | |
str(fecha.year)[2:4], | |
(fecha.day if fecha.day >= 10 else '0' + fecha.day.__str__()), | |
fecha.month if fecha.month >= 10 else '0' + fecha.month.__str__(), | |
str(fecha.year)[2:4], | |
) | |
return str(web_base) | |
web_base = genera_web_base() | |
print(web_base) | |
def cantidad_paginas(codigo_unico='71beef'): | |
m = None | |
for i in range(1, 100): | |
a = requests.get( | |
web_base + '%s-1440-71beef.jpg' % str(str(i) if i > 9 else '0' + str(i))).status_code | |
print(i, a) | |
if a == 404: | |
m = i | |
break | |
return m | |
maximo = cantidad_paginas() | |
print(maximo) | |
def genera_imagenes(fecha=getFecha(), web=web_base): | |
for i in range(1, maximo): | |
f = open(u'%s-%s.jpg' % (fecha, i if i > 9 else '0' + str(i)), 'wb') | |
f.write(requests.get( | |
'%s%s-1440-71beef.jpg' % ( | |
web, | |
i if i > 9 else '0' + str(i)) | |
).content) | |
def genera_diario(fecha=getFecha()): | |
genera_imagenes() | |
with open(u"%s.pdf" % fecha, "wb") as f: | |
listado_jpg = [] | |
for i in range(1, maximo): | |
listado_jpg.append(u'%s-%s.jpg' % (fecha, i if i > 9 else '0' + str(i))) | |
f.write(img2pdf.convert(listado_jpg)) | |
for i in listado_jpg: | |
remove(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment