forked from minimaxir/char-embeddings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_magic_text.py
44 lines (39 loc) · 1.56 KB
/
create_magic_text.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
import json
file_path = "/Users/maxwoolf/Downloads/AllCards.json"
separators = {
'pre': "[",
'name_manaCost': "@",
'manaCost_cardtype': "#",
'cardtype_text': "$",
'text_power': '%',
'power_toughness': '^',
'end': "]"
}
with open('magic_cards.txt', 'wb') as f:
with open(file_path, 'rb') as data:
cards = json.load(data)
names = cards.keys()
for name in names:
card = cards[name]
if not isinstance(card['name'], list):
manaCost = card.get('manaCost', '')
cardtype = card.get('type', '')
text = card.get('text', '').replace(
name, "~").replace("\n", "|")
power = card.get('power', '')
toughness = card.get('toughness', '')
card_processed = (separators['pre'] +
name +
separators['name_manaCost'] +
manaCost +
separators['manaCost_cardtype'] +
cardtype +
separators['cardtype_text'] +
text +
separators['text_power'] +
power +
separators['power_toughness'] +
toughness +
separators['end'] +
"\n")
f.write(card_processed.encode('utf-8'))