markup: process pdf improvements
This commit is contained in:
@ -61,34 +61,39 @@ def process_markup_pdf(pdf_path, username):
|
|||||||
|
|
||||||
pdf_name = Path(pdf_path).name
|
pdf_name = Path(pdf_path).name
|
||||||
dest_path = os.path.join(workdir, pdf_name)
|
dest_path = os.path.join(workdir, pdf_name)
|
||||||
|
print(f'copying pdf from {pdf_path}')
|
||||||
print(f'copying pdf to {dest_path}')
|
print(f'copying pdf to {dest_path}')
|
||||||
shutil.copy(pdf_path, dest_path)
|
shutil.copy(pdf_path, dest_path)
|
||||||
set_file_perms(dest_path)
|
set_file_perms(dest_path)
|
||||||
|
|
||||||
frm = str(make_header(decode_header(f'{user.get_full_name()} <{user.email}>')))
|
frm = str(make_header(decode_header(f'{user.get_full_name()} <{user.email}>')))
|
||||||
subject = str(make_header(decode_header(pdf_name)))
|
subject = str(make_header(decode_header(pdf_stem)))
|
||||||
|
|
||||||
process_pdf(dest_path, frm, subject, workdir)
|
|
||||||
|
|
||||||
|
|
||||||
def process_pdf(pdf_path, from_address, subject, workdir):
|
|
||||||
# find matches
|
# find matches
|
||||||
matches = find_marked_products(pdf_path, workdir, debug=0)
|
matches = find_marked_products(dest_path, workdir, debug=0)
|
||||||
if not matches:
|
if not matches:
|
||||||
print('no product matches')
|
print('no product matches')
|
||||||
reply_no_matches(from_address, subject)
|
# reply_no_matches(frm, subject)
|
||||||
return
|
return
|
||||||
|
|
||||||
print(f'{len(matches)} product matches')
|
print(f'{len(matches)} product matches')
|
||||||
|
|
||||||
# write spreadsheet
|
# write spreadsheet
|
||||||
pdf_stem = Path(pdf_path).stem
|
|
||||||
xls_path = write_spreadsheet(matches, workdir, pdf_stem)
|
xls_path = write_spreadsheet(matches, workdir, pdf_stem)
|
||||||
|
|
||||||
if xls_path:
|
if not xls_path:
|
||||||
# send reply
|
# TODO send error
|
||||||
print(f'wrote spreadsheet: {xls_path}')
|
|
||||||
reply(from_address, subject, xls_path, pdf_path)
|
|
||||||
else:
|
|
||||||
# send error
|
|
||||||
print(f'error creating spreadsheet')
|
print(f'error creating spreadsheet')
|
||||||
|
return
|
||||||
|
|
||||||
|
webdav_dir = Path(pdf_path).parent
|
||||||
|
xls_name = Path(xls_path).name
|
||||||
|
xls_webdav_path = os.path.join(webdav_dir, xls_name)
|
||||||
|
|
||||||
|
print(f'wrote spreadsheet: {xls_path}')
|
||||||
|
print(f'copying xls to {xls_webdav_path}')
|
||||||
|
|
||||||
|
shutil.copy(xls_path, xls_webdav_path)
|
||||||
|
set_file_perms(xls_webdav_path)
|
||||||
|
|
||||||
|
reply(frm, subject, xls_webdav_path, pdf_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user