diff --git a/hektor.py b/hektor.py index 67e848cdd9da60c577dd7490dc809674af5e653b..63d8a295da3e32bf595bb1864c44d6bd79062f3e 100644 --- a/hektor.py +++ b/hektor.py @@ -1,4 +1,5 @@ import argparse +import base64 import json import re import sys @@ -15,7 +16,8 @@ tasks_path = ('./assessment/section') users = './tst_active/row' solutions = './tst_solutions/row[@question_fi="%s"]' -lecturer_xpath = './MetaData/Lifecycle/Contribute[@Role="Author"]/Entity/text()' +lecturer_xpath = './MetaData/Lifecycle/Contribute[@Role="Author"]/Entity/text()' + def eat_qti(tree, only_of_type=('assSourceCode',), **kwargs): tasks = tree.xpath(tasks_path)[0] @@ -39,8 +41,12 @@ def eat_users(results_tree): for row in results_tree.xpath(users)} +def convert_code(text): + return base64.b64decode(text).decode('utf-8').split('\n') + + def eat_solutions(results_tree, task_id): - return {row.attrib['active_fi']: row.attrib['value1'] + return {row.attrib['active_fi']: convert_code(row.attrib['value1']) for row in results_tree.xpath(solutions % task_id)}