Spaces:
Running
Running
File size: 1,329 Bytes
7c52136 17dcef2 |
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 |
# Important: run this script from the parent directory
# (the root directory in this repository)
#
# python3 list_scripts/4_compile_from_legal_sets.py
import json
import pandas as pd
with open("data/middleschool.json") as json_data:
cards = json.loads(json_data.read())
# Create a pandas DataFrame with all cards from all legal sets
column_names = ["oracle_id", "name", "name_ja"]
middleschool_df = pd.DataFrame(columns=column_names)
for card in cards:
oracle_id = card["identifiers"]["scryfallOracleId"]
name = card["name"]
lang_ja = [lang for lang in card["foreignData"] if lang["language"] == "Japanese"]
# Some cards do not have a Japanese name
if len(lang_ja) > 0:
name_ja = lang_ja[0]["name"]
else:
name_ja = None
temporary_df = pd.DataFrame(
{"oracle_id": [oracle_id], "name": [name], "name_ja": [name_ja]}
)
middleschool_df = pd.concat([middleschool_df, temporary_df])
# For cards with multiple occurrences, put the rows that have the Japanese name on top
middleschool_df = middleschool_df.sort_values(by=["name", "name_ja"])
# For cards with multiple occurrences, delete all rows except for the top one
middleschool_df = middleschool_df.drop_duplicates(subset=["oracle_id"])
# Write a CSV file
middleschool_df.to_csv("data/middleschool_all_sets.csv")
|