Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if search query actually returns an item #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions sw/sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ async def person(self, ctx, person_id: Union[int,str]):
if response.status == 404:
return await ctx.send("Invalid Person ID.")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a string/query and not an ID per se, could this and the other ones in the string queries be converted to just "Invalid person/film/etc"?

person = json.loads(await response.text())
if person["count"] == 0:
return await ctx.send("No people found")
name = person["results"][0]["name"]
embed = discord.Embed(title=f"Person: {name}", description=HUMANDESCRIPTION[name], color=0x32CD32)
for key, value in person["results"][0].items():
Expand Down Expand Up @@ -213,6 +215,8 @@ async def planet(self, ctx, planet_id: Union[int,str]):
if response.status == 404:
return await ctx.send("Invalid Planet ID.")
planet = json.loads(await response.text())
if planet["count"] == 0:
return await ctx.send("No planets found")
name = planet["results"][0]["name"]
embed = discord.Embed(title=f"Planet: {name}", description=PLANETDESCRIPTION[name], color=0x800080)
for key, value in planet["results"][0].items():
Expand Down Expand Up @@ -318,6 +322,8 @@ async def film(self, ctx, film_id: Union[int,str]):
if response.status == 404:
return await ctx.send("Invalid Film ID.")
film = json.loads(await response.text())
if film["count"] == 0:
return await ctx.send("No films found")
name = film["results"][0]["title"]
embed = discord.Embed(title=f"Film: {name}; Page 1/4", color=0x0000FF)
for key, value in film["results"][0].items():
Expand Down Expand Up @@ -427,6 +433,8 @@ async def starship(self, ctx, starship_id: Union[int,str]):
if response.status == 404:
return await ctx.send("Invalid Starship ID.")
starship = json.loads(await response.text())
if starship["count"] == 0:
return await ctx.send("No starships found")
name = starship["results"][0]["name"]
embed = discord.Embed(title=f"Starship: {name}", description=STARSHIPDESCRIPTIONS[name], color=0x000000)
for key, value in starship["results"][0].items():
Expand Down Expand Up @@ -491,6 +499,8 @@ async def vehicle(self, ctx, vehicle_id: Union[int,str]):
if response.status == 404:
return await ctx.send("Invalid Vehicle ID.")
vehicle = json.loads(await response.text())
if vehicle["count"] == 0:
return await ctx.send("No vehicles found")
name = vehicle["results"][0]["name"]
embed = discord.Embed(title=f"Vehicle: {name}", description=VEHICLEDESCRIPTION[name], color=0x228B22)
for key, value in vehicle["results"][0].items():
Expand Down Expand Up @@ -561,6 +571,8 @@ async def species(self, ctx, species_id: Union[int,str]):
if response.status == 404:
return await ctx.send("Invalid Species ID.")
species = json.loads(await response.text())
if species["count"] == 0:
return await ctx.send("No species found")
name = species["results"][0]["name"]
embed = discord.Embed(title=f"Species: {name}", description=SPECIESDESCRIPTION[name], color=0xD2B48C)
embed.add_field(name="ID:", value=str(species_id))
Expand Down