forked from funkaoshi/randomcharacter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
troika_parser.py
54 lines (41 loc) · 1.18 KB
/
troika_parser.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
import collections
import json
with open("troika_backgrounds.txt") as f:
backgrounds_txt = collections.deque(f.readlines())
def nextline():
return backgrounds_txt and backgrounds_txt.popleft().strip()
backgrounds = []
while backgrounds_txt:
name = nextline()
description = nextline()
assert(nextline() == "")
assert(nextline() == "Possessions")
possessions = []
while True:
possession = nextline()
if not possession:
break
possessions.append(possession)
assert(nextline() == "Skills")
skills = []
while True:
skill = nextline()
if not skill:
break
skills.append(skill)
specials = []
if backgrounds_txt and backgrounds_txt[0].strip() == "Special":
backgrounds_txt.popleft()
while True:
special = backgrounds_txt and nextline()
if not special:
break
specials.append(special)
backgrounds.append({
"name": name,
"description": description,
"possessions": possessions,
"skills": skills,
"special": " ".join(specials)
})
print((json.dumps(backgrounds, indent=4)))