Skip to content

Commit

Permalink
Update api.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dtxc authored Dec 30, 2022
1 parent 0e82cf0 commit 1e31bd8
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ def __init__(self, api_key: str):

def get_uuid(self, player_name: str) -> str:
api_request = requests.get(f"https://api.mojang.com/users/profiles/minecraft/{player_name}")
return api_request.text
content = json.loads(api_request.content)
return content["id"]

# API Retrieval Commands
def get_auctions(self, *, page: int = 0):
def get_auctions(self, page: int = 0):
"""
Returns a `dict` of the 1000 latest auctions in Skyblock.
Optional args:
* `page`: View a specific page of auctions.
"""
api_request = requests.get(f"https://api.hypixel.net/skyblock/auctions?key={self.api_key}&page={page}")
api_request = requests.get(f"https://api.hypixel.net/skyblock/auctions?key={self.api_key}&page={page}").content
auctions = json.loads(api_request)
return auctions

Expand All @@ -29,23 +30,23 @@ def get_player_auctions(self, player_name: str):
Returns a `dict` of all Skyblock auctions from a particular player.
"""
player_uuid = self.get_uuid(player_name)
api_request = requests.get(f"https://api.hypixel.net/skyblock/auction?key={self.api_key}&player={player_uuid}")
api_request = requests.get(f"https://api.hypixel.net/skyblock/auction?key={self.api_key}&player={player_uuid}").content
player_auctions = json.loads(api_request)
return player_auctions

def get_news(self):
"""
Returns a `dict` of the latest Skyblock news from Hypixel.
"""
api_request = requests.get(f"https://api.hypixel.net/skyblock/news?key={self.api_key}")
api_request = requests.get(f"https://api.hypixel.net/skyblock/news?key={self.api_key}").content
news = json.loads(api_request)
return news

def get_bazaar_data(self):
"""
Returns a `dict` of Skyblock bazaar data.
"""
api_request = requests.get(f"https://api.hypixel.net/skyblock/bazaar?key={self.api_key}")
api_request = requests.get(f"https://api.hypixel.net/skyblock/bazaar?key={self.api_key}").content
bazaar_data = json.loads(api_request)
return bazaar_data

Expand All @@ -54,22 +55,22 @@ def get_player_profile(self, player_name: str):
Returns a `dict` of profile data on a player.
"""
player_uuid = self.get_uuid(player_name)
api_request = requests.get(f"https://api.hypixel.net/skyblock/profiles?key={self.api_key}&uuid={player_uuid}")
api_request = requests.get(f"https://api.hypixel.net/skyblock/profiles?key={self.api_key}&uuid={player_uuid}").content
player_profile_data = json.loads(api_request)
return player_profile_data

def get_collections(self):
"""
Returns a `dict` of information related to Skyblock Collections.
"""
api_request = requests.get("https://api.hypixel.net/resources/skyblock/collections")
api_request = requests.get("https://api.hypixel.net/resources/skyblock/collections").content
collections_data = json.loads(api_request)
return collections_data

def get_skills(self):
"""
Returns a `dict` of information related to Skyblock Skills.
"""
api_request = requests.get("https://api.hypixel.net/resources/skyblock/skills")
api_request = requests.get("https://api.hypixel.net/resources/skyblock/skills").content
collections_data = json.loads(api_request)
return collections_data

0 comments on commit 1e31bd8

Please sign in to comment.