From 7cb1f5051b831927a44421bdb7f184604ad4df9e Mon Sep 17 00:00:00 2001 From: Philipp Schrader Date: Sun, 5 May 2013 13:03:53 -0700 Subject: [PATCH] Adding a basic read_pdf.py script. This is intended to grow into the counterpart of generate_pdf.py. --- read_pdf.py | 36 ++++++++++++++++++++++++++++++++++++ scantron.py | 9 +++++++++ 2 files changed, 45 insertions(+) create mode 100755 read_pdf.py diff --git a/read_pdf.py b/read_pdf.py new file mode 100755 index 0000000..13f8216 --- /dev/null +++ b/read_pdf.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python2 + +import os +import sys +from argparse import ArgumentParser +from scantron import ScantronParser + +# Make this file easier to use by adding nice arguments +parser = ArgumentParser(description='Parse scanned scantron sheets.') +parser.add_argument( + 'data', + metavar='input_data', + help='File where the field data is stored. ' + + 'This must be a python script with an array called "data" ' + + 'of Field entries.') + +args = parser.parse_args() + +# If the file has a .py extension, we should still accept it +if args.data.endswith('.py'): + args.data = os.path.splitext(args.data)[0] + +# Import the file specified on the command line +try: + __import__(args.data) + data = sys.modules[args.data].data +except ImportError: + print('Failed to import %s.' % args.data) + quit(1) +except AttributeError: + print('Could not find data array.') + quit(1) + +# If everything went well, proceed to parse the filled scantron +st = ScantronParser() +st.scan(data, 'pages/page-1.jpg') diff --git a/scantron.py b/scantron.py index e97d8ac..5b39cc9 100755 --- a/scantron.py +++ b/scantron.py @@ -6,6 +6,15 @@ from qrcode import * +class ScantronParser: + def __init__(self): + pass + + + def scan(self, data, path): + pass + + class Scantron: def __init__(self, filename, spacing=0.3*inch): self._fontSize = 0.15*inch