Skip to content

Instantly share code, notes, and snippets.

@itzilly
Last active June 22, 2024 07:36
Show Gist options
  • Save itzilly/ae35b1d4ffeecc597eb8ea885b638f14 to your computer and use it in GitHub Desktop.
Save itzilly/ae35b1d4ffeecc597eb8ea885b638f14 to your computer and use it in GitHub Desktop.
if __name__ == "__main__":
url = "https://api.hypixel.net/v2/resources/skyblock/items"
r = requests.get(url)
data = r.json()
result = data.get('something', "Theres nothing here!")
# The second parameter in the .get method is the result, if it fails to find the first argument.
# So if 'something' isn't in the data, then result will be "Theres nothing here!"
# This is very useful if you're wanting to get intager numbers, as you can look for
# any variable and if it does not exist, it will automatically be set to whatver you pass in
# ex.
# skywars_level = data.get('skywars_level', 0)
# If the player has never played skywars, they will not have a skywars level. With the
# get function used like this, you'll get 0 for skywars_level instead of an IndexError exception
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment