Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate splitting of tutor evaluation #238

Open
miterion opened this issue Jun 12, 2021 · 0 comments
Open

Integrate splitting of tutor evaluation #238

miterion opened this issue Jun 12, 2021 · 0 comments

Comments

@miterion
Copy link
Member

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant