-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion_example.py
118 lines (95 loc) · 4.47 KB
/
question_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os
from question_api_client import QuestionApiClient
template_id = 2122
random_seed = 256951
right_answer = [["30", "13"]]
wrong_answer = [["40", "13"]]
def example_blank_render(question_api_client, template_id, random_seed):
question_content = question_api_client.get_question(template_id, random_seed=random_seed)
html = render_question_responsive(question_content['question_html'])
with open('example_blank_render.html', 'w') as example_file:
example_file.write(html)
def example_right_answer(question_api_client, template_id, random_seed, right_answer):
right_data = {
'question1a': right_answer[0][0],
'question1b': right_answer[0][1]
}
question_content = question_api_client.mark_question(template_id, random_seed, right_data)
html = render_question_responsive(question_content['question_html'])
with open('example_right_answer.html', 'w') as example_file:
example_file.write(html)
def example_wrong_answer(question_api_client, template_id, random_seed, wrong_answer):
wrong_data = {
'question1a': wrong_answer[0][0],
'question1b': wrong_answer[0][1]
}
question_content = question_api_client.mark_question(template_id, random_seed, wrong_data)
html = render_question_responsive(question_content['question_html'])
with open('example_wrong_answer.html', 'w') as example_file:
example_file.write(html)
def example_blank_answer(question_api_client, template_id, random_seed):
blank_data = {
'question1a': '',
'question1b': ''
}
question_content = question_api_client.mark_question(template_id, random_seed, blank_data)
html = render_question_responsive(question_content['question_html'])
with open('example_blank_answer.html', 'w') as example_file:
example_file.write(html)
def example_blank_render_basic(template_id, random_seed):
question_api_client = QuestionApiClient(theme='basic')
question_content = question_api_client.get_question(template_id, random_seed=random_seed)
html = render_question_basic(question_content['question_html'])
with open('example_blank_render_basic.html', 'w') as example_file:
example_file.write(html)
def render_question_responsive(question_html):
return """
<!DOCTYPE html>
<html>
<head>
<title>Question Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="{api_host}/static/themes/emas/question-api/question-api.min.css"/>
</head>
<body>
<main class="sv-region-main emas sv">
<div id="monassis" class="monassis monassis--practice monassis--question-api">
<div class="question-wrapper">
<div class="question-content">{question_html}</div>
</div>
</div>
</main>
</body>
<script src="{api_host}/static/themes/emas/node_modules/mathjax/MathJax.js?config=TeX-MML-AM_HTMLorMML-full"></script>
<script src="{api_host}/static/themes/emas/question-api/question-api.min.js"></script>
</html>""".format(question_html=question_html, api_host=os.environ['question_api_host'])
def render_question_basic(question_html):
return """
<!DOCTYPE html>
<html>
<head>
<title>Question API</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="{api_host}/static/themes/mobile/question-api/question-api.min.css"/>
</head>
<body class="za-mobile mobile sv">
<div id="margins">
<div id="content">
<div id="monassis" class="monassis monassis--practice monassis--maths monassis--question-api">
<div class="question-wrapper">
<div class="question-content">
{question_html}
</div>
</div>
</div>
</div>
</div>
</body>
</html>""".format(question_html=question_html, api_host=os.environ['question_api_host'])
question_api_client = QuestionApiClient()
question_api_client.verify_token()
example_blank_render(question_api_client, template_id, random_seed)
example_right_answer(question_api_client, template_id, random_seed, right_answer)
example_wrong_answer(question_api_client, template_id, random_seed, wrong_answer)
example_blank_answer(question_api_client, template_id, random_seed)
example_blank_render_basic(template_id, random_seed)