Skip to content

Integrate splitting of tutor evaluation #238

Description

@miterion

There is currently the following script but it would be nice to integrate this into the software

from PyPDF2 import PdfFileReader, PdfFileWriter
import sys
import subprocess
import re
from shlex import quote

reg = re.compile(r'(?:Gruppe:\s*)(\d*)')
inputfilename = sys.argv[1]
inputfilename_safe = quote(inputfilename)
input = PdfFileReader(open(inputfilename, 'rb'))
pages = input.getNumPages()
gruppe = 1

output = PdfFileWriter()
outfilename_prefix = inputfilename.split('.pdf',1)[0]
# We do not know the group number yet so we do a dumy replace
outfilename = '{}-Gruppe-{}.pdf'.format(outfilename_prefix, '{}')
for i in range(1, pages + 1):
    ret = subprocess.getoutput('pdftotext -f {0} -l {0} {1} -'.format(i, inputfilename_safe))
    if 'für Frage' in ret and i != 1:
        outfile = open(outfilename.format(gruppe), 'wb')
        output.write(outfile)
        outfile.close()
        output = PdfFileWriter()
        gruppe = int(reg.search(ret).group(1))
    output.addPage(input.getPage(i - 1))
outfile = open(outfilename.format(gruppe), 'wb')
gruppe += 1
output.write(outfile)
outfile.close()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions