Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
Latest commit
42 lines (31 loc) · 1.27 KB
/
Copy pathapi.py
File metadata and controls
42 lines (31 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
"""Hypixel API v2 客户端 (https://api.hypixel.net, API-Key 请求头认证)"""
importjson
from .utilsimportget_url
API_BASE_URL='https://api.hypixel.net/v2'
classHypixelAPI:
def__init__(self, api_key):
self.api_key=api_key
defget(self, endpoint, params=None, cache=300):
"""请求 API, 返回 (dict|None, http_status)"""
query=dict(paramsor {})
query['key'] =self.api_key
body, status=get_url(API_BASE_URL+endpoint, query, cache)
ifnotbody:
returnNone, status
try:
returnjson.loads(body), status
exceptValueError:
returnNone, status
defplayer_by_name(self, name):
returnself.get('/player', {'name': name})
defguild_by_player(self, uuid):
returnself.get('/guild', {'player': uuid})
defstatus(self, uuid):
returnself.get('/status', {'uuid': uuid}, cache=10)
defrecent_games(self, uuid):
returnself.get('/recentgames', {'uuid': uuid}, cache=45)
defskyblock_profile(self, profile_id):
returnself.get('/skyblock/profile', {'profile': profile_id})
defskyblock_auction(self, profile_id):
returnself.get('/skyblock/auction', {'profile': profile_id})