Skip to content

Commit

Permalink
Added support for intro texts of online tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bartvbl committed Jun 30, 2017
1 parent 06c0b2c commit 469e055
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,26 +1246,35 @@ def processOnlineTest(institution, pathThusFar, nttUrl, nttID, session):
has_submitted_answer = False

if has_submitted_answer and is_student:
test_info_elements = online_test_document.find_class('itsl-detailed-info')

test_info_elements = online_test_document.find_class('itsl-detailed-info')

# Extracting test information
info_file_contents = ''

for info_element in test_info_elements:
for info_list_element in info_element:
if len(info_list_element) >= 1:
entry_name = info_list_element[0].text_content()
else:
entry_name = ''
if len(info_list_element) >= 2:
entry_content = info_list_element[1].text_content()
info_file_contents += info_list_element[0].text_content()
info_file_contents += ' '
info_file_contents += info_list_element[1].text_content()
info_file_contents += '\n'
else:
entry_content = ''
if not (entry_name == '' and entry_content == ''):
info_file_contents += entry_name + ' ' + entry_content + '\n'
# Dump whatever is inside the line if the indication was unclear.
info_file_contents += info_list_element.text_content() + '\n'

testIntro = online_test_document.find_class('NTT_TestDescriptionIntro')

intro_text = ''.encode('utf-8')
if len(testIntro > 0):
# Assuming there is only one of these
testIntro = testIntro[0]
intro_text += '\n\nTest Intro:\n\n'.encode('utf-8')
intro_text += etree.tostring(testIntro, encoding='utf-8', with_comments=False, pretty_print=True)


bytesToTextFile(info_file_contents.encode('utf-8'), dumpDirectory + '/Test Information' + output_text_extension)
bytesToTextFile(info_file_contents.encode('utf-8') + intro_text, dumpDirectory + '/Test Information' + output_text_extension)

# Download test answers

Expand Down

0 comments on commit 469e055

Please sign in to comment.