import requests
import json
from tqdm import tqdm


BASE_URL = "https://www.dnd5eapi.co"

spell_resp = requests.get(BASE_URL + "/api/2014/spells")
spell_list = json.loads(spell_resp.text)['results']

spells = []
for spell in tqdm(spell_list):
    url = spell.pop("url")
    spell_data_resp = requests.get(BASE_URL + url)
    if spell_data_resp.text:
        spells.append(json.loads(spell_data_resp.text))

with open('dnd_spells.json', 'w') as fh:
    json.dump(spells, fh, indent=2)



