forked from jmatzen/quizsail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcvt3.py
30 lines (27 loc) · 762 Bytes
/
cvt3.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
from pprint import pprint
import json
items=[]
with open('prea.txt','r') as f:
state = 0
item = None
for line in f.readlines():
line = line.rstrip()
if (len(line)==0):
continue
if line.startswith('Question'):
if item!=None:
items.append(item)
item={}
ofs = line.index(':')+1
item['q'] = line[ofs:].lstrip()
item['c'] = []
elif line.startswith(' '):
if line[1]=='*':
item['a'] = [line[4:]]
item['c'].append(line[4:])
else:
item['c'].append(line[3:])
else:
item['q']+='<BR>'+line
items.append(item)
print(json.dumps(items,indent=2))