Printing exception reasion. Updated path. Fixed issue with output file name. Added script to check if the PDF exists and adds it to a list if it doesn't.
This commit is contained in:
30
filecheck.py
Normal file
30
filecheck.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import os
|
||||||
|
from openpyxl import load_workbook
|
||||||
|
|
||||||
|
|
||||||
|
path = 'U:\\ICP STUFF\\PDF\\'
|
||||||
|
|
||||||
|
wb = load_workbook('Missing.xlsx')
|
||||||
|
sh1 = wb.get_sheet_by_name('Assets')
|
||||||
|
sh2 = wb.get_sheet_by_name('Missing')
|
||||||
|
failedrow = 2
|
||||||
|
|
||||||
|
for row in sh1.iter_rows(min_row=2):
|
||||||
|
|
||||||
|
itemNumber = row[0].value
|
||||||
|
title = row[1].value
|
||||||
|
|
||||||
|
file = path+str(itemNumber)+'.pdf'
|
||||||
|
print(row[0].value)
|
||||||
|
|
||||||
|
# Gets PDF info, splits the 'Page size' key by the space and sets the width and height values
|
||||||
|
if os.path.exists(file):
|
||||||
|
# print(file)
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print('%s - %s missing' % (str(itemNumber), title))
|
||||||
|
sh2.cell(row=failedrow, column=1).value = itemNumber
|
||||||
|
sh2.cell(row=failedrow, column=2).value = title
|
||||||
|
failedrow = failedrow + 1
|
||||||
|
|
||||||
|
wb.save('Missing.xlsx')
|
||||||
9
main.py
9
main.py
@@ -4,7 +4,7 @@ from openpyxl import load_workbook
|
|||||||
|
|
||||||
path = 'U:\\CreativeConnectionMove\\Assets\\'
|
path = 'U:\\CreativeConnectionMove\\Assets\\'
|
||||||
# outputPath = 'C:\\Users\\ddembinski\\Desktop\\thumb\\'
|
# outputPath = 'C:\\Users\\ddembinski\\Desktop\\thumb\\'
|
||||||
outputPath = 'U:\\thumb\\'
|
outputPath = 'U:\\ICP STUFF\\'
|
||||||
|
|
||||||
|
|
||||||
wb = load_workbook('fomoPDFs.xlsx')
|
wb = load_workbook('fomoPDFs.xlsx')
|
||||||
@@ -15,7 +15,7 @@ failedrow = 2
|
|||||||
for row in sh1.iter_rows(min_row=2):
|
for row in sh1.iter_rows(min_row=2):
|
||||||
|
|
||||||
file = row[3].value
|
file = row[3].value
|
||||||
outfile = row[2].value
|
outfile = str(row[2].value)
|
||||||
|
|
||||||
print(row[0].value)
|
print(row[0].value)
|
||||||
|
|
||||||
@@ -43,12 +43,13 @@ for row in sh1.iter_rows(min_row=2):
|
|||||||
images = pdf2image.convert_from_path(path + file, poppler_path='c:\\poppler\\bin',
|
images = pdf2image.convert_from_path(path + file, poppler_path='c:\\poppler\\bin',
|
||||||
output_folder=outputPath + '128', single_file=True,
|
output_folder=outputPath + '128', single_file=True,
|
||||||
size=(None, 128), fmt='jpeg', output_file=outfile)
|
size=(None, 128), fmt='jpeg', output_file=outfile)
|
||||||
shutil.copy(path + file, outputPath + 'PDF\\' + outfile + '.pdf')
|
shutil.copy(path + file, outputPath + 'PDF\\' + str(outfile) + '.pdf')
|
||||||
except:
|
except Exception as e:
|
||||||
print('%s - %s conversion failed' % (row[0].value, row[3].value))
|
print('%s - %s conversion failed' % (row[0].value, row[3].value))
|
||||||
sh2.cell(row=failedrow, column=1).value = row[0].value
|
sh2.cell(row=failedrow, column=1).value = row[0].value
|
||||||
sh2.cell(row=failedrow, column=2).value = row[2].value
|
sh2.cell(row=failedrow, column=2).value = row[2].value
|
||||||
sh2.cell(row=failedrow, column=3).value = row[3].value
|
sh2.cell(row=failedrow, column=3).value = row[3].value
|
||||||
|
print(e)
|
||||||
failedrow = failedrow + 1
|
failedrow = failedrow + 1
|
||||||
|
|
||||||
wb.save('fomoPDFs.xlsx')
|
wb.save('fomoPDFs.xlsx')
|
||||||
|
|||||||
Reference in New Issue
Block a user