Source code for uw.local.teaching.bin.crowdmark_upload_pdf
"""Manual upload of PDF master to Crowdmark.
Python process to upload a given PDF file to Crowdmark manually.
"""
import argparse
from sys import stdin, exit
from uw.sql.wrap import open_psycopg2_db_service_cursor
from ..db.cursor import Cursor
from ..db.crowdmark import crowdmark_upload_pdf
[docs]def main ():
parser = argparse.ArgumentParser ()
parser.add_argument ('--exam', required=True, type=int, metavar='exam_id')
args = parser.parse_args ()
cursor = open_psycopg2_db_service_cursor (cursor_class=Cursor)
exam_id = args.exam
exam = cursor.execute_optional_tuple ("select crowdmark_exam_code from exam_exam natural left join exam_exam_crowdmark where exam_id = %(exam_id)s", exam_id=exam_id)
if exam is None:
print ('No such examination')
exit (-1)
elif exam.crowdmark_exam_code is None:
print ('No Crowdmark exam code set')
exit (-1)
master_pdf = stdin.buffer.read ()
success, response = crowdmark_upload_pdf (cursor, exam, master_pdf)
if not success:
print ('Status %d was reported attempting to upload the PDF, with the following message:' % response.status)
print (response.data.decode ())