zyqinglong/mt.py
2024-01-04 12:00:17 +08:00

160 lines
5.4 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.

"""
mt论坛自动签到
支持多用户运行
添加变量mtluntan
账号密码用&隔开
多用户用@隔开
例如账号110086 密码1001
账号11234 密码1234
则变量为10086&1001@1234&1234
export mtluntan=""
cron: 0 0,7 * * *
const $ = new Env("mt论坛");
"""
import requests
import re
import os
import time
#qq:1628708538
#设置ua
ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
session = requests.session()
#获取ip
ipdi = requests.get('http://ifconfig.me/ip', timeout=6).text.strip()
print('============📣初始化📣============')
print(ipdi)
#判断国内外地址
dizhi = f'http://ip-api.com/json/{ipdi}?lang=zh-CN'
pdip = requests.get(url=dizhi, timeout=6).json()
country = pdip['country']
if '中国' == country:
print(country)
else:
print(f'{country}无法访问论坛')
exit()
print('==================================')
all_print_list = [] # 用于记录所有 myprint 输出的字符串
# 用于记录所有 print 输出的字符串,暂时实现 print 函数的sep和end
def myprint(*args, sep=' ', end='\n', **kwargs):
global all_print_list
output = ""
# 构建输出字符串
for index, arg in enumerate(args):
if index == len(args) - 1:
output += str(arg)
continue
output += str(arg) + sep
output = output + end
all_print_list.append(output)
# 调用内置的 print 函数打印字符串
print(*args, sep=sep, end=end, **kwargs)
# 发送通知消息
def send_notification_message(title):
try:
from sendNotify import send
send(title, ''.join(all_print_list))
except Exception as e:
if e:
print('发送通知消息失败!')
def main(username,password):
headers={'User-Agent': ua}
session.get('https://bbs.binmt.cc/member.php?mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login',headers=headers)
chusihua = session.get('https://bbs.binmt.cc/member.php?mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login',headers=headers)
#print(re.findall('loginhash=(.*?)">', chusihua.text))
loginhash = re.findall('loginhash=(.*?)">', chusihua.text)[0]
formhash = re.findall('formhash" value="(.*?)".*? />', chusihua.text)[0]
denurl = f'https://bbs.binmt.cc/member.php?mod=logging&action=login&loginsubmit=yes&handlekey=login&loginhash={loginhash}&inajax=1'
data = {'formhash': formhash,'referer': 'https://bbs.binmt.cc/forum.php','loginfield': 'username','username': username,'password': password,'questionid': '0','answer': '',}
denlu = session.post(headers=headers, url=denurl, data=data).text
#print(denlu)
if '欢迎您回来' in denlu:
#获取分组、名字
fzmz = re.findall('欢迎您回来,(.*?),现在', denlu)[0]
myprint(f'{fzmz}:登录成功')
#获取formhash
zbqd = session.get('https://bbs.binmt.cc/k_misign-sign.html', headers=headers).text
formhash = re.findall('formhash" value="(.*?)".*? />', zbqd)[0]
#签到
qdurl=f'https://bbs.binmt.cc/plugin.php?id=k_misign:sign&operation=qiandao&format=text&formhash={formhash}'
qd = session.get(url=qdurl, headers=headers).text
qdyz = re.findall('<root><(.*?)</root>', qd)[0]
myprint(f'签到状态:{qdyz}')
if '已签' in qd:
huoqu(formhash)
else:
myprint('登录失败')
return True
def huoqu(formhash):
headers = {'User-Agent': ua}
huo = session.get('https://bbs.binmt.cc/k_misign-sign.html', headers=headers).text
pai = re.findall('您的签到排名:(.*?)</div>', huo)[0]
jiang = re.findall('id="lxreward" value="(.*?)">', huo)[0]
myprint(f'签到排名{pai},奖励{jiang}金币')
#退出登录,想要多用户必须,执行退出
tuic = f'https://bbs.binmt.cc/member.php?mod=logging&action=logout&formhash={formhash}'
session.get(url=tuic, headers=headers)
if __name__ == '__main__':
#账号
username = '林lin'
#username.encode("utf-8")
#密码
password = '13977922831'
if 'mtluntan' in os.environ:
fen = os.environ.get("mtluntan").split("@")
myprint(f'查找到{len(fen)}个账号')
myprint('==================================')
for duo in fen:
username,password = duo.split("&")
try:
main(username,password)
myprint('============📣结束📣============')
except Exception as e:
pdcf = False
pdcf1 = 1
while pdcf != True:
if pdcf1 <=3:
pdcf = main(username,password)
else:
pdcf = True
else:
myprint('不存在青龙、github变量')
if username == '' or password == '':
myprint('本地账号密码为空')
exit()
else:
try:
main(username,password)
except Exception as e:
pdcf = False
pdcf1 = 1
while pdcf != True:
if pdcf1 <=3:
pdcf = main(username,password)
else:
pdcf = True
try:
send_notification_message(title='mt论坛') # 发送通知
except Exception as e:
print('小错误')