Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions services/spell_lookup_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import json
import requests

class SpellLookupService:
@staticmethod
def lookup(spell_name):
try:
with open('spells.json', 'r') as file:
data = json.load(file)
except FileNotFoundError:
print("spells.json file not found.")
return

spell_name = spell_name.lower()

spells = data.get('results', [])

for spell in spells:
if spell.get('name', '').lower() == spell_name:
print(f"\nSpell Found!\n")
print(f"Name: {spell.get('name', 'Unknown')}")
print(f"Index: {spell.get('index', 'Unknown')}")
print(f"URL: {spell.get('url', 'Unknown')}")

full_url = f"https://www.dnd5eapi.co{spell.get('url')}"
try:
response = requests.get(full_url)
if response.status_code == 200:
full_spell_data = response.json()
print(f"\n--- Full Spell Details ---")
print(f"Description: {full_spell_data.get('desc', ['No description'])[0]}")
print(f"Level: {full_spell_data.get('level', 'Unknown')}")
print(f"Casting Time: {full_spell_data.get('casting_time', 'Unknown')}")
print(f"Duration: {full_spell_data.get('duration', 'Unknown')}")
print(f"Range: {full_spell_data.get('range', 'Unknown')}")
else:
print("Failed to fetch full spell details (API error).")
except requests.RequestException:
print("Network error while trying to fetch full spell details.")

return

print("Spell not found.\n")
7 changes: 7 additions & 0 deletions writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import matplotlib.pyplot as plt
import os
from tqdm.auto import tqdm
from services.spell_lookup_service import SpellLookupService

cmap = plt.get_cmap('viridis')
#---------Functions for creating unique binary numbers------
Expand Down Expand Up @@ -310,7 +311,12 @@ def draw_attribute(level = None,rang = None, area = None,
parser.add_argument("--legend",help = "bool to print legend or not (0 = False,1 = True)")
parser.add_argument("--breakdown",help = "bool to control whether to breakdown the lines with colour")
parser.add_argument("-ah", "--arg_help",help = "Prints the available options for the chosen attributes",action=argparse.BooleanOptionalAction)
parser.add_argument("--lookup", help="Lookup a spell from spells.json")
args = parser.parse_args()
if args.lookup:
SpellLookupService.lookup(args.lookup)
exit()


if args.arg_help:
if args.range:
Expand Down Expand Up @@ -375,6 +381,7 @@ def draw_attribute(level = None,rang = None, area = None,
else:
school = args.school

savename = args.savename
draw_spell(level,rang,area,dtype,school,title = title,legend = legend,
base_fn = bases.polygon,shape_fn = line_shapes.straight,
breakdown = breakdown,savename = savename)
Expand Down