Skip to content
Snippets Groups Projects
Verified Commit e2fd0777 authored by Jan Maximilian Michal's avatar Jan Maximilian Michal
Browse files

Allow broken matrikulation numbers in xls

parent 3b6eac53
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -48,24 +48,31 @@ user_t = namedtuple('user_head', 'name matrikel_no')
task_head_re = re.compile(r'^Quellcode Frage (?P<title>.*?) ?(\d{8})?$')
# nor parsing the weird mat no
matno_re = re.compile(r'^(?P<matrikel_no>\d{8})-(\d+)-(\d+)$')
matno_re = re.compile(r'^(?P<matrikel_no>\d+)-(\d+)-(\d+)$')
TABWIDTH = 4
def converter(infile, usernames=None, number_of_tasks=0,):
def converter(infile, usernames=None, number_of_tasks=0):
# Modify these iterators in order to change extraction behaviour
def sheet_iter_meta(sheet):
def sheet_iter_meta(sheet, silent=True):
""" yield first and second col entry as tuple of (name, matnr) """
for row in (sheet.row(i) for i in range(1, sheet.nrows)):
match = re.search(matno_re, row[1].value)
if match:
if not silent and len(match.group('matrikel_no')) != 8:
print('[WARN] %s has odd matrikelno %s' %
(row[0].value, match.group('matrikel_no')))
yield row[0].value, match.group('matrikel_no')
else:
if not silent:
print('[WARN] could not parse row %s' % row[0])
yield row[0].value, row[1].value
def sheet_iter_data(sheet):
""" yields all source code titel and code tuples """
""" yields all source code title and code tuples """
def row(i):
return sheet.row(i)
for top, low in ((row(i), row(i + 1)) for i in range(sheet.nrows - 1)):
......@@ -77,7 +84,7 @@ def converter(infile, usernames=None, number_of_tasks=0,):
meta, *data = open_workbook(infile, open(os.devnull, 'w')).sheets()
# nice!
name2mat = dict(sheet_iter_meta(meta))
name2mat = dict(sheet_iter_meta(meta, silent=False))
assert len(name2mat) == len(data), '{} names != {} sheets'.format(len(name2mat), len(data)) # noqa
# from xls to lists and namedtuples
......
......@@ -4,7 +4,7 @@ from setuptools import setup
setup(
name='hektor',
version='0.3.2',
version='0.3.3',
description='A QTI-XML/XLS to JSON converter for humans',
author='Jan Maximilian Michal',
author_email='mail@janmax.org',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment