markup: process Documents inklist annotations
This commit is contained in:
@ -2,13 +2,16 @@ from __future__ import absolute_import, unicode_literals
|
||||
from celery import task, shared_task
|
||||
from celery.utils.log import get_task_logger
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import datetime
|
||||
import fileinput
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import smtplib
|
||||
import sys
|
||||
|
||||
from pathlib import Path
|
||||
from os.path import basename, dirname, isfile
|
||||
|
||||
from email.feedparser import FeedParser
|
||||
from email.message import EmailMessage
|
||||
@ -75,7 +78,6 @@ def process_attachment(from_address, subject, attachment):
|
||||
print(f'Using pdf name: {pdf_name}')
|
||||
|
||||
pdf_base = Path(pdf_name).stem
|
||||
|
||||
workdir = os.path.join(WORKDIR, clean_path(from_address), pdf_base)
|
||||
ensure_dir(workdir)
|
||||
pdf_path = os.path.join(workdir, pdf_name)
|
||||
@ -84,6 +86,32 @@ def process_attachment(from_address, subject, attachment):
|
||||
att.write(attachment.get_payload(decode=True))
|
||||
set_file_perms(pdf_path)
|
||||
|
||||
process_pdf(pdf_path, from_address, subject, workdir)
|
||||
|
||||
|
||||
@shared_task(on_failure=on_fail_handler)
|
||||
def process_markup_pdf(pdf_path, user):
|
||||
if not Path(pdf_path).is_file():
|
||||
print(f'No pdf - exiting ({pdf_path})')
|
||||
return
|
||||
|
||||
pdf_stem = Path(pdf_path).stem
|
||||
workdir = os.path.join(WORKDIR, clean_path(user.username), clean_path(pdf_stem))
|
||||
ensure_dir(workdir)
|
||||
|
||||
pdf_name = Path(pdf_path).name
|
||||
dest_path = os.path.join(workdir, pdf_name)
|
||||
print(f'copying pdf to {dest_path}')
|
||||
shutil.copy(pdf_path, dest_path)
|
||||
set_file_perms(dest_path)
|
||||
|
||||
frm = str(make_header(decode_header(f'{user.get_full_name()} <{user.email}>')))
|
||||
subject = str(make_header(decode_header(pdf_name)))
|
||||
|
||||
process_pdf(dest_path, frm, subject, workdir)
|
||||
|
||||
|
||||
def process_pdf(pdf_path, from_address, subject, workdir):
|
||||
# find matches
|
||||
matches = find_marked_products(pdf_path, workdir, debug=0)
|
||||
if not matches:
|
||||
@ -94,7 +122,8 @@ def process_attachment(from_address, subject, attachment):
|
||||
print(f'{len(matches)} product matches')
|
||||
|
||||
# write spreadsheet
|
||||
xls_path = write_spreadsheet(matches, workdir, pdf_base)
|
||||
pdf_stem = Path(pdf_path).stem
|
||||
xls_path = write_spreadsheet(matches, workdir, pdf_stem)
|
||||
|
||||
if xls_path:
|
||||
# send reply
|
||||
|
||||
Reference in New Issue
Block a user