I have a small problem with the empty field (without text) in the api in the description field, I would like that when searching for a kind of weapon it appears that it does not have a description
This is the code I’m using:
import json
import requests
args = input("Escribe: ")
rarity = input("rareza: ")
response = requests.get("https://jose89fcb.es/apifortnite/weapons.php")
data = response.json()
for api in data['weapons']:
if args == api["name"].strip():
if rarity == api["rarity"]:
print(f'Desc: {api["description"]}')
In this case, the empty field is in the description and I would like an error "No description" to appear.
Could someone help me, thank you very much!
>Solution :
Try to check if it is empty:
import json
import requests
args = input("Escribe: ")
rarity = input("rareza: ")
response = requests.get("https://jose89fcb.es/apifortnite/weapons.php")
data = response.json()
for api in data['weapons']:
if args == api["name"].strip():
if rarity == api["rarity"]:
description = api["description"]
if description:
print(f'Desc: {description}')
else:
print("No description")