-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf_to_json.py
60 lines (47 loc) · 1.34 KB
/
pdf_to_json.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
import PyPDF2
import pandas as pd
import json
questions = []
response = []
true = []
#FORMAT FIRST LINE: Data,
data = pd.read_csv('FV.csv', sep=',',encoding= 'unicode_escape')
for d in range(0, len(data["Data"]), 4):
questions.append(data["Data"][d])
response.append([data["Data"][d+1], data["Data"][d+2], data["Data"][d+3]])
if data["Data"][d+1][0] == 'X':
true.append(1)
response[-1][0] = response[-1][0].replace("X ", "")
elif data["Data"][d+2][0] == 'X':
true.append(2)
response[-1][1] = response[-1][1].replace("X ", "")
elif data["Data"][d+3][0] == 'X':
true.append(3)
response[-1][2] = response[-1][2].replace("X ", "")
else:
print("error X not detected in response")
print("---------Q---------")
print(len(questions))
print("---------R---------")
print(len(response))
print("---------T---------")
print(len(true))
data = {}
data['All'] = []
data['Wrong'] = []
for i, q in enumerate(questions):
data['All'].append({
'question': q,
'choices': response[i],
'True': true[i]
})
data['Wrong'].append({
'question': q,
'choices': response[i],
'True': true[i],
'try': 0
})
final_data = {}
final_data['Data'] = data
with open('data_for_memory.txt', 'w') as outfile:
json.dump(final_data, outfile)