2023-06-17 17:34:18 +08:00

76 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from typing import Tuple
from ruamel.yaml import CommentedMap
from app.log import logger
from app.plugins.autosignin.sites import _ISiteSigninHandler
from app.utils.string import StringUtils
class BTSchool(_ISiteSigninHandler):
"""
学校签到
"""
# 匹配的站点Url每一个实现类都需要设置为自己的站点Url
site_url = "pt.btschool.club"
# 已签到
_sign_text = '每日签到'
@classmethod
def match(cls, url) -> bool:
"""
根据站点Url判断是否匹配当前站点签到类大部分情况使用默认实现即可
:param url: 站点Url
:return: 是否匹配如匹配则会调用该类的signin方法
"""
return True if StringUtils.url_equal(url, cls.site_url) else False
def signin(self, site_info: CommentedMap) -> Tuple[bool, str]:
"""
执行签到操作
:param site_info: 站点信息含有站点Url、站点Cookie、UA等信息
:return: 签到结果信息
"""
site = site_info.get("name")
site_cookie = site_info.get("cookie")
ua = site_info.get("ua")
render = site_info.get("render")
proxy = site_info.get("proxy")
logger.info(f"{site} 开始签到")
# 判断今日是否已签到
html_text = self.get_page_source(url='https://pt.btschool.club',
cookie=site_cookie,
ua=ua,
proxy=proxy,
render=render)
if not html_text:
logger.error(f"签到失败,请检查站点连通性")
return False, f'{site}】签到失败,请检查站点连通性'
if "login.php" in html_text:
logger.error(f"签到失败Cookie失效")
return False, f'{site}】签到失败Cookie失效'
# 已签到
if self._sign_text not in html_text:
logger.info(f"今日已签到")
return True, f'{site}】今日已签到'
html_text = self.get_page_source(url='https://pt.btschool.club/index.php?action=addbonus',
cookie=site_cookie,
ua=ua,
proxy=proxy,
render=render)
if not html_text:
logger.error(f"签到失败,签到接口请求失败")
return False, f'{site}】签到失败,签到接口请求失败'
# 签到成功
if self._sign_text not in html_text:
logger.info(f"签到成功")
return True, f'{site}】签到成功'