-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_py_set_to_js.py
28 lines (19 loc) · 1.07 KB
/
convert_py_set_to_js.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
### MODIFY THESE
SET_NAME = "throne_of_eldraine"
SET_ACRONYM = "eld"
from mtga.set_data import all_mtga_cards
cards = [card for card in all_mtga_cards.cards if card.set == SET_ACRONYM.upper()]
### END MODIFY
cards.sort(key=lambda x: int(x.mtga_id))
header = """const {{ CardPool, Card }} = require('./models.js')
let {} = new CardPool({{name: "{}", cards: []}})
""".format(SET_NAME, SET_NAME)
footer = """module.exports = {{ {}: {} }}""".format(SET_NAME, SET_NAME)
total_str = header
for card in cards:
card_fstr = '{}.addCard(new Card({{ mtgaID: {}, setNumber: {}, name: "{}", prettyName: "{}", cardType: "{}", set: "{}", subTypes: "{}", colorIdentity: {}, colors: {}, rarity: "{}", cost: {}, collectible: {} }}))'
card_line = card_fstr.format(SET_NAME, card.mtga_id, card.set_number, card.name, card.pretty_name, card.card_type, card.set, card.sub_types, card.color_identity, card.colors, card.rarity, card.cost, str(card.collectible).lower())
total_str += card_line + "\n"
total_str += "\n\n" + footer
with open("{}.js".format(SET_ACRONYM), "w") as wf:
wf.write(total_str)