Skip to content

Commit 307d9c6

Browse files
committed
json_convert: Fix support for updated JSON structure
1 parent ba44572 commit 307d9c6

File tree

2 files changed

+32
-102
lines changed

2 files changed

+32
-102
lines changed

in2lambda/json_convert/json_convert.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,20 @@ def converter(
3434
output["title"] = "Question " + str(i + 1)
3535

3636
# add main text to the question file
37-
output["masterContent"]["blocks"][0]["data"] = ListQuestions[i].main_text
37+
output["masterContent"] = ListQuestions[i].main_text
3838

3939
# add parts to the question file
4040
if ListQuestions[i].parts:
41-
output["parts"][0]["content"]["blocks"][0]["data"] = (
42-
ListQuestions[i].parts[0].text
43-
)
44-
output["parts"][0]["workedSolution"][0]["content"]["blocks"][0]["data"] = (
41+
output["parts"][0]["content"] = ListQuestions[i].parts[0].text
42+
output["parts"][0]["workedSolution"][0]["content"] = (
4543
ListQuestions[i].parts[0].worked_solution
4644
)
4745
for j in range(1, len(ListQuestions[i].parts)):
4846
output["parts"].append(deepcopy(template["parts"][0]))
49-
output["parts"][j]["content"]["blocks"][0]["data"] = (
50-
ListQuestions[i].parts[j].text
47+
output["parts"][j]["content"] = ListQuestions[i].parts[j].text
48+
output["parts"][j]["workedSolution"][0]["content"] = (
49+
ListQuestions[i].parts[j].worked_solution
5150
)
52-
output["parts"][j]["workedSolution"][0]["content"]["blocks"][0][
53-
"data"
54-
] = (ListQuestions[i].parts[j].worked_solution)
5551

5652
# Output file
5753
filename = "Question " + str(i + 1)
Lines changed: 26 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,26 @@
1-
{
2-
"type": "DRAFT",
3-
"id": "NA",
4-
"versionId": "NA",
5-
"hasBeenPublished": false,
6-
"createdAt": "",
7-
"updatedAt": "",
8-
"title": "Question title here",
9-
"number": 0,
10-
"masterContent": {
11-
"blocks": [
12-
{
13-
"__typename": "TextContentBlock",
14-
"id": "N/A",
15-
"data": "Question here",
16-
"type": "MILKDOWN"
17-
}
18-
]
19-
},
20-
"parts": [
21-
{
22-
"id": "NA",
23-
"universalPartId": "",
24-
"content": {
25-
"blocks": [
26-
{
27-
"__typename": "TextContentBlock",
28-
"id": "N/A",
29-
"data": "\n",
30-
"type": "MILKDOWN"
31-
}
32-
]
33-
},
34-
"workedSolution": [
35-
{
36-
"id": "NA",
37-
"content": {
38-
"blocks": [
39-
{
40-
"__typename": "TextContentBlock",
41-
"id": "N/A",
42-
"data": "",
43-
"type": "MILKDOWN"
44-
}
45-
]
46-
}
47-
}
48-
],
49-
"answerContent": {
50-
"blocks": [
51-
{
52-
"__typename": "TextContentBlock",
53-
"id": "N/A",
54-
"data": "",
55-
"type": "MILKDOWN"
56-
}
57-
]
58-
},
59-
60-
"tutorial": [
61-
{
62-
"id": "NA",
63-
"content": {
64-
"blocks": [
65-
{
66-
"__typename": "TextContentBlock",
67-
"id": "N/A",
68-
"data": "",
69-
"type": "MILKDOWN"
70-
}
71-
]
72-
}
73-
},
74-
{
75-
"id": "NA",
76-
"content": {
77-
"blocks": [
78-
{
79-
"__typename": "TextContentBlock",
80-
"id": "N/A",
81-
"data": "",
82-
"type": "MILKDOWN"
83-
}
84-
]
85-
}
86-
}
87-
],
88-
89-
"responseAreas": []
90-
}
91-
]
92-
}
1+
{
2+
"isPublished": false,
3+
"masterContent": "Top level question here",
4+
"parts": [
5+
{
6+
"answer": "",
7+
"content": "Part text here",
8+
"responseArea": [],
9+
"tutorial": [],
10+
"universalPartId": "N/A",
11+
"workedSolution": [
12+
{
13+
"content": "Part worked solution here",
14+
"id": "N/A",
15+
"title": ""
16+
}
17+
]
18+
}
19+
],
20+
"questionSettings": {
21+
"displayFinalAnswer": true,
22+
"displayStructuredTutorial": true,
23+
"displayWorkedSolution": true
24+
},
25+
"title": "Question title here"
26+
}

0 commit comments

Comments
 (0)