book generation
This commit is contained in:
parent
851b7ab4f9
commit
e3e6820621
1 changed files with 38 additions and 35 deletions
|
@ -257,51 +257,54 @@ def main():
|
||||||
print("Genero i libretti")
|
print("Genero i libretti")
|
||||||
os.makedirs('books', exist_ok=True)
|
os.makedirs('books', exist_ok=True)
|
||||||
for pagstart in range(1, len(vgo_dict), 50):
|
for pagstart in range(1, len(vgo_dict), 50):
|
||||||
pdfWriter = PyPDF2.PdfFileWriter()
|
|
||||||
|
|
||||||
book_num = int(pagstart / 50) + 1
|
book_num = int(pagstart / 50) + 1
|
||||||
pagend = min(book_num * 50, len(vgo_dict))
|
pagend = min(book_num * 50, len(vgo_dict))
|
||||||
|
|
||||||
print(book_num)
|
|
||||||
|
|
||||||
# aggiungere copertina
|
|
||||||
pdfWriter.addPage(copertina(str(pagstart).zfill(3) + " - " + str(pagend).zfill(3)))
|
|
||||||
|
|
||||||
pdfWriter.addBlankPage()
|
book_name = os.path.join('books', 'vgo_' + str(book_num).zfill(2) + '.pdf')
|
||||||
|
if not os.path.isfile(book_name):
|
||||||
|
pdfWriter = PyPDF2.PdfFileWriter()
|
||||||
|
print(book_num)
|
||||||
|
|
||||||
indtext = ""
|
# aggiungere copertina
|
||||||
for vgo_num in [str(x).zfill(3) for x in range(pagstart, pagend + 1)]:
|
pdfWriter.addPage(copertina(str(pagstart).zfill(3) + " - " + str(pagend).zfill(3)))
|
||||||
pdf_name = os.path.join('pdf', vgo_num + '.pdf')
|
|
||||||
|
|
||||||
try:
|
|
||||||
#print(vgo_num + " - " + vgo_dict[vgo_num])
|
|
||||||
indtext = indtext + vgo_num + "\t" + vgo_dict[vgo_num] + "\n"
|
|
||||||
pdfFileObj = open(pdf_name, 'rb')
|
|
||||||
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
|
|
||||||
pageObj = pdfReader.getPage(0)
|
|
||||||
pdfWriter.addPage(pageObj)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
for i in range(0, 8 - ((((pagend - 1) % 50) + 1 + 5) % 8)):
|
|
||||||
pdfWriter.addBlankPage()
|
pdfWriter.addBlankPage()
|
||||||
|
|
||||||
# aggiungere indice
|
indtext = ""
|
||||||
for indpag in indice(indtext):
|
for vgo_num in [str(x).zfill(3) for x in range(pagstart, pagend + 1)]:
|
||||||
pdfWriter.addPage(indpag)
|
pdf_name = os.path.join('pdf', vgo_num + '.pdf')
|
||||||
|
|
||||||
|
try:
|
||||||
|
#print(vgo_num + " - " + vgo_dict[vgo_num])
|
||||||
|
indtext = indtext + vgo_num + "\t" + vgo_dict[vgo_num] + "\n"
|
||||||
|
pdfFileObj = open(pdf_name, 'rb')
|
||||||
|
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
|
||||||
|
pageObj = pdfReader.getPage(0)
|
||||||
|
pdfWriter.addPage(pageObj)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
for i in range(0, 8 - ((((pagend - 1) % 50) + 1 + 5) % 8)):
|
||||||
|
pdfWriter.addBlankPage()
|
||||||
|
|
||||||
#Aggiungere pagina finale
|
# aggiungere indice
|
||||||
#pdfWriter.addBlankPage()
|
for indpag in indice(indtext):
|
||||||
pdfFileObj = open("quarta.pdf", 'rb')
|
pdfWriter.addPage(indpag)
|
||||||
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
|
|
||||||
pageObj = pdfReader.getPage(0)
|
|
||||||
pdfWriter.addPage(pageObj)
|
|
||||||
|
|
||||||
book_name = os.path.join('books', 'vgo_' + str(book_num).zfill(2) + '.pdf')
|
#Aggiungere pagina finale
|
||||||
with open(book_name, 'wb') as pdfOutput:
|
#pdfWriter.addBlankPage()
|
||||||
pdfWriter.write(pdfOutput)
|
pdfFileObj = open("quarta.pdf", 'rb')
|
||||||
|
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
|
||||||
|
pageObj = pdfReader.getPage(0)
|
||||||
|
pdfWriter.addPage(pageObj)
|
||||||
|
|
||||||
|
with open(book_name, 'wb') as pdfOutput:
|
||||||
|
pdfWriter.write(pdfOutput)
|
||||||
|
|
||||||
|
# # Genera indice
|
||||||
|
# with open("index.txt", 'w') as handler:
|
||||||
|
# for key in sorted(vgo_dict):
|
||||||
|
# handler.write(key + ' - ' + vgo_dict[key] + '\n')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue