|
| 1 | +"""Used for accessing the Skyblock API.""" |
| 2 | +import requests |
| 3 | +import json |
| 4 | + |
| 5 | +class Skyblock: |
| 6 | + def __init__(self, api_key: str): |
| 7 | + self.api_key = api_key |
| 8 | + |
| 9 | + def get_uuid(self, player_name: str) -> str: |
| 10 | + api_request = requests.get(f"https://api.mojang.com/users/profiles/minecraft/{player_name}") |
| 11 | + return api_request.text |
| 12 | + |
| 13 | + # Make API retrieval commands here |
| 14 | + def get_auctions(self, *, player_name: str = None): |
| 15 | + """ |
| 16 | + Returns a `dict` of the 1000 latest auctions in Skyblock. |
| 17 | + |
| 18 | + Optional args: |
| 19 | + * `player_name`: Shows auctions only from that player. |
| 20 | + """ |
| 21 | + if player_name is not None: |
| 22 | + player_uuid = self.get_uuid(player_name) |
| 23 | + api_request = requests.get(f"https://api.hypixel.net/skyblock/auction?key={self.api_key}&player={player_uuid}") |
| 24 | + return api_request.text |
| 25 | + else: |
| 26 | + api_request = requests.get(f"https://api.hypixel.net/skyblock/auctions?key={self.api_key}") |
| 27 | + auctions = json.loads(api_request) |
| 28 | + return auctions |
| 29 | + |
| 30 | + def get_news(self): |
| 31 | + """ |
| 32 | + Returns a `dict` of the latest Skyblock news from Hypixel. |
| 33 | + """ |
| 34 | + api_request = requests.get(f"https://api.hypixel.net/skyblock/news?key={self.api_key}") |
| 35 | + news = json.loads(api_request) |
| 36 | + return news |
| 37 | + |
| 38 | + def get_bazaar_data(self): |
| 39 | + """ |
| 40 | + Returns a `dict` of Skyblock bazaar data. |
| 41 | + """ |
| 42 | + api_request = requests.get(f"https://api.hypixel.net/skyblock/bazaar?key={self.api_key}") |
| 43 | + bazaar_data = json.loads(api_request) |
| 44 | + return bazaar_data |
| 45 | + |
| 46 | + def get_player_profile(self, player_name: str): |
| 47 | + """ |
| 48 | + Returns a `dict` of profile data on a player. |
| 49 | + """ |
| 50 | + player_uuid = self.get_uuid(player_name) |
| 51 | + api_request = requests.get(f"https://api.hypixel.net/skyblock/profiles?key={self.api_key}&uuid={player_uuid}") |
| 52 | + player_profile_data = json.loads(api_request) |
| 53 | + return player_profile_data |
0 commit comments