Spaces:
Running
Running
Alejandro Cremades
commited on
Commit
•
3a6c7d1
1
Parent(s):
8aeef8e
Add additional fields to card list
Browse files
list_scripts/8_add_other_fields.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
|
5 |
+
def add_other_fields(row: pd.DataFrame) -> pd.DataFrame:
|
6 |
+
print(f"{row['name']} | {row['oracle_id']}")
|
7 |
+
for index, card in enumerate(cards):
|
8 |
+
if card["identifiers"]["scryfallOracleId"] == row["oracle_id"]:
|
9 |
+
row["mw"] = card["manaValue"]
|
10 |
+
row["rarity"] = card["rarity"]
|
11 |
+
row["text"] = card["text"] if "text" in card else None
|
12 |
+
row["type"] = card["type"]
|
13 |
+
row["power"] = card["power"] if "power" in card else None
|
14 |
+
row["toughness"] = card["toughness"] if "toughness" in card else None
|
15 |
+
colors = card["colors"]
|
16 |
+
row["w"] = True if "W" in colors else False
|
17 |
+
row["u"] = True if "U" in colors else False
|
18 |
+
row["b"] = True if "B" in colors else False
|
19 |
+
row["r"] = True if "R" in colors else False
|
20 |
+
row["g"] = True if "G" in colors else False
|
21 |
+
row["c"] = True if len(colors) < 1 else False
|
22 |
+
return row
|
23 |
+
return row
|
24 |
+
|
25 |
+
|
26 |
+
middleschool_df = pd.read_csv("output/middleschool.csv")
|
27 |
+
with open("data/middleschool.json") as json_data:
|
28 |
+
cards = json.loads(json_data.read())
|
29 |
+
|
30 |
+
middleschool_df = middleschool_df.apply(add_other_fields, axis=1)
|
31 |
+
|
32 |
+
middleschool_df.to_csv("output/middleschool_extra_fields.csv")
|
33 |
+
middleschool_df.to_json("output/middleschool_extra_fields.json")
|
output/middleschool_extra_fields.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
output/middleschool_extra_fields.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|