From 8e84722fec6c747dacec4cfd91ee68ae62139115 Mon Sep 17 00:00:00 2001
From: janmax <j.michal@stud.uni-goettingen.de>
Date: Tue, 20 Mar 2018 19:59:46 +0100
Subject: [PATCH] Allow broken matrikulation numbers in xls

---
 lib/xls.py | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/xls.py b/lib/xls.py
index 0e13a16..9ac0a5a 100755
--- a/lib/xls.py
+++ b/lib/xls.py
@@ -48,24 +48,30 @@ 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 +83,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
-- 
GitLab