-
-
Save itzilly/ae35b1d4ffeecc597eb8ea885b638f14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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