Skip to content

Commit

Permalink
fix: 修复房间号获取格式
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowsSov8forUs committed May 15, 2024
1 parent f9e0af5 commit abb7afa
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='tsugu-api-python',
version='1.1.0',
version='1.1.1',
author='WindowsSov8',
author_email='[email protected]',
description='Tsugu BanGDream Bot 的功能 API 统合包',
Expand Down
7 changes: 5 additions & 2 deletions tsugu_api/_bandoristation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from tsugu_api import settings
from tsugu_api._network import Api
from tsugu_api._typing import _StationRoom
from tsugu_api.exception import RoomSubmitFailure
from tsugu_api.exception import RoomQueryFailure, RoomSubmitFailure

BANDORI_STATION_URL = 'https://api.bandoristation.com/index.php'

Expand Down Expand Up @@ -47,7 +47,10 @@ def query_room_number() -> list[_StationRoom]:
}

# 发送请求
return Api(
response = Api(
BANDORI_STATION_URL,
proxy=settings.backend_proxy
).get(params).json()
if response['status'] == 'failure':
raise RoomQueryFailure(response['response'])
return response['response']
9 changes: 8 additions & 1 deletion tsugu_api/exception.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
class RoomSubmitFailure(BaseException):
'''车牌号上传失败'''
'''房间号上传失败'''
def __init__(self, response: str) -> None:
'''初始化'''
self.message = response
return

class RoomQueryFailure(BaseException):
'''房间号获取失败'''
def __init__(self, response: str) -> None:
'''初始化'''
self.message = response
Expand Down
9 changes: 6 additions & 3 deletions tsugu_api_async/_bandoristation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tsugu_api_async import settings
from tsugu_api_async._network import Api
from tsugu_api_async._typing import _StationRoom
from tsugu_api_async.exception import RoomSubmitFailure
from tsugu_api_async.exception import RoomQueryFailure, RoomSubmitFailure

BANDORI_STATION_URL = 'https://api.bandoristation.com/index.php'

Expand Down Expand Up @@ -55,5 +55,8 @@ async def query_room_number() -> list[_StationRoom]:
BANDORI_STATION_URL,
proxy=settings.backend_proxy
).get(params)
if isinstance(response, Response): return response.json()
else: return await response.json()
if isinstance(response, Response): response = response.json()
else: response = await response.json()
if response['status'] == 'failure':
raise RoomQueryFailure(response['response'])
return response['response']
9 changes: 8 additions & 1 deletion tsugu_api_async/exception.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
class RoomSubmitFailure(BaseException):
'''车牌号上传失败'''
'''房间号上传失败'''
def __init__(self, response: str) -> None:
'''初始化'''
self.message = response
return

class RoomQueryFailure(BaseException):
'''房间号获取失败'''
def __init__(self, response: str) -> None:
'''初始化'''
self.message = response
Expand Down

0 comments on commit abb7afa

Please sign in to comment.