cqwu-ehall/cqwu/methods/epay/get_balance.py
brian 60c32861ea
Support get score
Co-authored-by: brian <brian@xtaolabs.com>
2023-03-08 20:48:12 +08:00

29 lines
734 B
Python

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