PT项目加入多线程模式

This commit is contained in:
rm 2024-11-20 16:54:13 +08:00
parent 9cb1bda913
commit a093a7a6f7
4 changed files with 104 additions and 27 deletions

View File

@ -10,6 +10,7 @@
url = "https://sharkpt.net"
cookie = ""
level = 3
flag = 1
['Audiences 观众/奥迪']
url = "https://audiences.me"
@ -217,9 +218,10 @@ url = "https://ourbits.club"
cookie = ""
level = 1
label = "十三大"
flag = 1
['PTerClub【PT之友俱乐部/猫站】' ]
url = "https://ourbits.club"
url = "https://pterclub.com"
cookie = ""
level = 1
label = "十三大"
@ -245,7 +247,7 @@ label = "影视,有声书,音乐,综合"
['btschool']
url = "https://pt.btschool.club"
cookie = "cf_clearance=GMf29NYLF6pgqZSpG4dbakMfL7dxFScTufyaLJt5BVM-1726732110-1.2.1.1-3HZ8qDHZ3ix3ISMr7kMxysfWbj5oY3lH5Plri_N1LtE8ifjcSeaJ..jCX5p13uIdrrIebFrXB44I7Zg0QT7l7wwZuITlX2joR_7UyiytVos5jAx_K8_ey4tuK89au4RKjYBmMkP1OBgwEwBy1atLWzkJh.JBfMvIN7M5HHtEgHrep9yNdhbrVxQAwzyz2IjXyaVvAvlantQoY5csnRGugVOZOVkZCM53ifKSELWLfUty0gtvu7pgWAxilBYDaQ5ZjAo77VffujuaYfF_l0ZH5.44.D5Wdlaub8iH9BGNo1oTbXV.Q1PEGcgAHG97MVlmePdsLcgK8.dqV9zquieIQlzI4_hRsZn6gJGpKVsLiBSYxlGV7TkYWbstQx5EkQCePZCGw4ERfJE3UMu0gEu1hwvVEEir638tw5m.XNXQmxjQYk7PLOTK5X2E41tTpD28; c_secure_uid=MTM4NTQ2; c_secure_pass=5eea7234b66710a8f6346d88d00d56a4; c_secure_ssl=eWVhaA%3D%3D; c_secure_tracker_ssl=eWVhaA%3D%3D; c_secure_login=bm9wZQ%3D%3D"
cookie = "cf_clearance=sntngeGiRRILzV56kgNcq_LV2OD0R7TBa6idECpWKKE-1732070383-1.2.1.1-mTasoHQiz6L8QH8.bKO.BCWQgito1D_qp87qLxbREUx__xuhM_4U.450bADQp6G76Paah8_6mLr3eEY3yi5yqCFKdYsBwBOyhhRi2QJSOpHSp7GNmWaKYWx72g0GrL.b8dAhhqf2SAzkEyQXs_kWV9s6kONT4HfNjD8ACN8VVJlLhnwjVDiFy1Dc8W3b4okLuCcwIWEo7jmdCJckZzItPjxzGBk5Pc5BAjoq_9MvK73eD2bG9WAhTCw4qObhBsEBQ9ub3MZuJWXv.l96OtB_XasgBPvupytF8j2h4lb2.gp_HqxMn6kK9Nz61kk8xau2Ka3gCmDYJ5OYe6I7KcBXJU8YRHkSFlqh_kg3wQWA0nFjFbQTzyRdsUKhzQa.c6rljxuOCUmgwBgso5ADlf0A56EpptPpFwzfEYmGfjhG3r6HLwT.CTcmmTadkw7oqwbB; c_secure_uid=MTM4NTQ2; c_secure_pass=5eea7234b66710a8f6346d88d00d56a4; c_secure_ssl=eWVhaA%3D%3D; c_secure_tracker_ssl=eWVhaA%3D%3D; c_secure_login=bm9wZQ%3D%3D"
attendance_uri = "/index.php?action=addbonus"
level = 3
label = "教育、培训"

View File

@ -37,7 +37,7 @@ class PtOperation:
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
}
def attendances(self, section_name, section_data):
async def attendances(self, section_name, section_data):
"""
签到
:param section_name:
@ -45,9 +45,9 @@ class PtOperation:
:param url:
:return:
"""
res_txt = f"开始对 [{section_name}] 进行签到操作...,签到结果:"
url, cookie, attendance_uri = section_data.get('url'), section_data.get('cookie'), section_data.get(
'attendance_uri')
res_text, log_txt = "", ""
self.headers["cookie"] = cookie
# cookie不为空时候可以签到
if cookie is not None and len(cookie.strip()) > 0:
@ -57,26 +57,35 @@ class PtOperation:
url = url + attendance_uri
else:
url = url + "/attendance.php"
for _ in range(5):
self.headers["referer"] = url
for i in range(5):
try:
print(url)
response_result = requests.get(url, headers=self.headers)
print(response_result.text)
print(response_result.status_code)
if response_result.status_code == 200:
res_txt = res_txt + '签到成功!'
logger.info(res_txt)
print(self.headers)
print("=" * 20)
print(response_result.text)
if response_result.status_code == 200 or response_result.text in "签到成功":
res_text = '签到成功!'
break
except Exception as e:
time.sleep(2)
else:
res_txt = res_txt + f"{res_txt} 5次出现错误请关注{url}"
logger.error(res_txt)
pushme("签到错误提示:" + section_name, res_txt)
pushplus_bot("签到错误提示:" + section_name, res_txt)
res_text = f"签到失败,网站请求结果 {response_result.status_code}"
break
except Exception:
time.sleep(2)
res_text = f"{i + 1} 次出现错误,请关注!!!"
finally:
log_txt = f"开始对 [{section_name}] 进行签到操作! 请求连接为:[{url}],签到结果:[{res_text}]"
logger.info(log_txt)
else:
# log_txt = f"开始对 [{section_name}] 进行签到操作! 请求连接为:[{url}],签到结果:[{res_text}]"
# logger.error(log_txt)
pushme("签到错误提示:" + section_name, log_txt)
pushplus_bot("签到错误提示:" + section_name, log_txt)
self.headers["cookie"] = ""
def signup(self, section_name, section_data):
async def signup(self, section_name, section_data):
"""
是否开注册
:return:
@ -102,7 +111,7 @@ class PtOperation:
soup = BeautifulSoup(html, 'html.parser')
text_content = soup.find(class_='text').get_text()
print(text_content)
except Exception as e:
except Exception:
logger.error(f"{text} , 页面无法解析,请知晓!!!")
logger.info("=" * 100)
@ -117,9 +126,9 @@ class PtOperation:
elif response.status_code == 200:
return response.text
else:
logger.error(f"{text} , 出现错误code码是{response.status_code}, {response.text}")
logger.error(f"{text} , 出现错误code码是{response.status_code}")
return ""
except Exception as e:
except Exception:
time.sleep(2)
else:
logger.error(f"{text} , 5次出现错误无法访问")
@ -147,7 +156,7 @@ class PtOperation:
elif res['status'] == 'error':
logger.error(f"{text} , 访问返回 {res['message']} ")
return ""
except Exception as e:
except Exception:
time.sleep(2)
else:
logger.error(f"{text} , 5次出现错误无法访问")

View File

@ -1,8 +1,13 @@
import asyncio
import toml
from fsspec.asyn import loop
from PT.pt_get_data import PtGetData
from PT.pt_operation import PtOperation
pt_opt = PtOperation()
def get_section_name_by_name(name):
with open('../PT/pt_config.toml', 'r', encoding='utf-8') as file:
@ -14,7 +19,7 @@ def get_section_name_by_name(name):
return True, section_name, section_data
def attendances_junit(name):
async def attendances_junit(name):
"""
PT签到测试
:param name:
@ -22,10 +27,10 @@ def attendances_junit(name):
"""
flag, section_name, section_data = get_section_name_by_name(name)
if flag:
PtOperation().attendances(section_name, section_data)
await pt_opt.attendances(section_name, section_data)
def signup_junit(name):
async def signup_junit(name):
"""
PT开注测试
:param name:
@ -33,7 +38,7 @@ def signup_junit(name):
"""
flag, section_name, section_data = get_section_name_by_name(name)
if flag:
PtOperation().signup(section_name, section_data)
await PtOperation().signup(section_name, section_data)
def get_pt_data_junit(name):
@ -42,6 +47,7 @@ def get_pt_data_junit(name):
PtGetData().get_data(section_name, section_data)
# attendances_junit("btschool")
signup_junit("PTLSP 零食铺")
# asyncio.run(attendances_junit("PTVicomo 象站"))
asyncio.run(signup_junit("Audiences 观众/奥迪"))
# get_pt_data_junit("pttime")

View File

@ -1,9 +1,69 @@
import asyncio
import toml
from PT.pt_operation import PtOperation
'''
new Env('PT自动签到和开注检测');
0 0 15 * * ?
'''
toml_file = 'PT/pt_config.toml'
async def attendances():
"""
签到
:return:
"""
pt_opt = PtOperation()
try:
with open(toml_file, 'r', encoding='utf-8') as file:
config_data = toml.load(file)
# 迭代每个 section
for section_name, section_data in config_data.items():
url, cookie, flag = section_data.get('url'), section_data.get('cookie'), section_data.get('flag')
if flag != 1 and cookie is not None and len(cookie.strip()) > 0:
print(f"Processing section: {section_name} --- {section_data.get('url')}")
# 签到
await pt_opt.attendances(section_name, section_data)
except FileNotFoundError:
print(f"Error: The file '{toml_file}' was not found.")
except toml.TomlDecodeError as e:
print(f"Error decoding TOML: {e}")
async def signup():
"""
开注提醒
:return:
"""
pt_opt = PtOperation()
try:
with open(toml_file, 'r', encoding='utf-8') as file:
config_data = toml.load(file)
# 迭代每个 section
for section_name, section_data in config_data.items():
url, cookie, flag = section_data.get('url'), section_data.get('cookie'), section_data.get('flag')
if flag != 1:
print(f"Processing section: {section_name} --- {section_data.get('url')}")
# 签到
await pt_opt.signup(section_name, section_data)
except FileNotFoundError:
print(f"Error: The file '{toml_file}' was not found.")
except toml.TomlDecodeError as e:
print(f"Error decoding TOML: {e}")
# 拉取网站数据
# 做种
if __name__ == '__main__':
PtOperation().opt()
# PtOperation().opt()
loop = asyncio.get_event_loop()
# 使用 asyncio.gather 可以运行多个异步任务
results = loop.run_until_complete(asyncio.gather(
attendances(), signup()
))
# print(results)