-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_prep.py
78 lines (55 loc) · 1.78 KB
/
data_prep.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from pprint import pprint
import codecs
import sys
from get_ability import *
import re
from mtgjson import CardDb
#create db
db = CardDb.from_file(db_file='AllSets.json')
#read in our list of cards to check
with open('ORI.json', encoding="utf-8") as f:
lines = f.read()
print(type(lines))
lines = json.loads(lines)
#x = str(lines).encode("utf-8")
#print(x)
#print(str(lines['cards']).encode('utf-8'))
#getlist of cards
card_list = []
for key in lines['cards']:
if "<class 'str'>" in key['name']:
continue
name =key['name'].encode('utf-8').decode('UTF-8')
card = db.cards_by_name[name]
if "Creature" == card.types[0]:
if len(card.colors) == 1:
card_list.append(card)
#get the values we want from the list of cards
for item in card_list:
print("##",item.name)
if item.power == "*":
adjusted_power = "*"
elif item.power == "0":
adjusted_power = -1
elif "+" in item.power:
value = item.power.split("+")
adjusted_power = int(value[0]) / int(item.cmc)
else:
adjusted_power = int(item.power)/int(item.cmc)
if item.toughness == "*":
adjusted_toughness = "*"
elif item.toughness == "0":
adjusted_toughness = -1
elif "+" in item.toughness:
value = item.toughness.split("+")
adjusted_toughness = int(value[0]) / int(item.cmc)
else:
adjusted_toughness = int(item.toughness)/int(item.cmc)
tf = ""
if len(item.subtypes) == 2:
tf = item.subtypes[1]
ability = get_ability(item)
print(str(item.cmc) + "," + str(adjusted_power) + "," + str(adjusted_toughness) + "," + item.subtypes[0] + "," + tf + "," + ability + "," + item.colors[0])