qnloft-spider/main_pt.py

70 lines
1.8 KiB
Python
Raw Normal View History

2024-11-20 08:54:13 +00:00
import asyncio
import toml
2023-12-26 15:18:46 +00:00
from PT.pt_operation import PtOperation
'''
2023-12-27 02:12:19 +00:00
new Env('PT自动签到和开注检测');
0 0 15 * * ?
2023-12-26 15:18:46 +00:00
'''
2024-11-20 08:54:13 +00:00
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}")
# 拉取网站数据
# 做种
2023-12-26 15:18:46 +00:00
if __name__ == '__main__':
2024-11-20 08:54:13 +00:00
# PtOperation().opt()
loop = asyncio.get_event_loop()
# 使用 asyncio.gather 可以运行多个异步任务
results = loop.run_until_complete(asyncio.gather(
attendances(), signup()
))
# print(results)