2022-08-10 15:12:43 +00:00
|
|
|
from typing import Optional
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
import cqwu
|
2023-03-08 12:48:12 +00:00
|
|
|
from cqwu.errors.auth import CookieError
|
2022-08-10 15:12:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GetBalance:
|
|
|
|
async def get_balance(
|
|
|
|
self: "cqwu.Client",
|
|
|
|
) -> Optional[str]:
|
|
|
|
"""
|
|
|
|
获取校园卡余额
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: 余额
|
|
|
|
"""
|
2023-03-08 12:48:12 +00:00
|
|
|
url = "http://218.194.176.214:8382/epay/thirdapp/balance"
|
|
|
|
html = await self.oauth(url)
|
2022-08-10 15:12:43 +00:00
|
|
|
if not html:
|
2023-03-08 12:48:12 +00:00
|
|
|
raise CookieError()
|
|
|
|
if html.url != url:
|
|
|
|
raise CookieError()
|
2022-08-10 15:12:43 +00:00
|
|
|
soup = BeautifulSoup(html.text, "lxml")
|
|
|
|
try:
|
|
|
|
return soup.find_all("div", "weui-cell__ft")[2].next
|
|
|
|
except (ValueError, TypeError, KeyError, IndexError):
|
|
|
|
return ""
|