Discuz!论坛农场脚本
本帖最后由 Velens 于 2023-12-8 00:55 编辑功能介绍:
Discuz!论坛农场脚本,以某洛论坛为例,支持微信推送
等级不够,values没有放全,高等级请自行通过F12补充
自行修改headers和xxx参数,支持云。函数和openwrt挂载
脚本代码:
import requests,time,re
session=requests.session()
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
#获取登录窗口中的loginhash和formhash
def get_login_window():
url='https://www.horou.com/member.php?mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login'
r=session.get(url,headers=headers)
#获取loginhash
p=r.text.find('loginhash')+len('loginhash')+1
loginhash=r.text
#获取formhash
p=r.text.find('formhash')+len('formhash" value="')
formhash=r.text
return (loginhash,formhash)
#登录
def login(loginhash,formhash,username,password):
url='https://www.horou.com/member.php?mod=logging&action=login&loginsubmit=yes&handlekey=login&loginhash='+loginhash+'&inajax=1'
data={'formhash':formhash,
'referer':'https://www.horou.com/forum.php',
'username':username,
'password':password,
'questionid':'0',
'answer':''}
r=session.post(url,headers=headers,data=data)
if 'succeedhandle_login' in r.text:
return ',登录成功'
else:
return ',登录失败'
#获取formhash
def get_formhash():
url='https://www.horou.com/'
r=session.get(url,headers=headers)
p=r.text.find('formhash')+len('formhash=')
formhash=r.text
return formhash
#收获
def harvest(formhash,jfid):
url='https://www.horou.com/plugin.php?id=jnfarm&do=harvest&jfid=' + jfid + '&formhash=' + formhash + '&inajax=1&ajaxtarget=theun'
r=session.get(url,headers=headers)
if "收割成功" in r.text:
return f"\n第{jfid}块地:收割成功,"
elif "收割时间未到" in r.text:
return f"\n第{jfid}块地:时间未到,"
elif "体力不足" in r.text:
return f"\n第{jfid}块地:体力不足,"
else:
return f"\n第{jfid}块地:没有作物,"
#播种
def plantseed(formhash,seed,jfid):
url='https://www.horou.com/plugin.php?id=jnfarm&do=plantseed&seed=' + seed + '&jfid=' + jfid + '&formhash=' + formhash + '×tamp=&jhash=&inajax=1&ajaxtarget=theuns'
r=session.get(url,headers=headers)
if "播种成功" in r.text:
return "播种成功,"
elif "当前已有其他作物生长中" in r.text:
return "已有作物,"
else:
return "没有种子"
#成熟
def normal(formhash,jfid):
url='https://www.horou.com/plugin.php?id=jnfarm&do=normal&ac=thisfarm&jfid=' + jfid + '&formhash=' + formhash + '×tamp=&inajax=1&ajaxtarget=try'
r=session.get(url,headers=headers)
p=r.text.find('2023-')+len('2023-02-11 ')
normal=r.text
return normal
#仓库
def store(prod):
url='https://www.horou.com/plugin.php?id=jnfarm&do=normal&ac=store&inajax=1&ajaxtarget=try'
r=session.get(url,headers=headers)
p=r.text.find(f"seedqty[{prod}]")
if p != -1:
value=r.text
seedqty = re.findall(r'="(.+?)"', value)
else:
seedqty = "0"
p=r.text.find(f"prodqty[{prod}]")
if p != -1:
value=r.text
prodqty = re.findall(r'="(.+?)"', value)
else:
prodqty = "0"
p=r.text.find(f"fertqty")
if p != -1:
value=r.text
fertqty = re.findall(r'="(.+?)"', value)
else:
fertqty = "0"
return seedqty,prodqty,fertqty
#信息
def userinfo():
url='https://www.horou.com/plugin.php?id=jnfarm&do=normal&ac=userinfo&inajax=1&ajaxtarget=us'
r=session.get(url,headers=headers)
p=r.text.find(f"layui-icon layui-icon-tips")
if p != -1:
value=r.text
tili = re.findall(r'\d+', value)
else:
tili = "0"
return tili
#出售
def sold(formhash,prod,prodqty):
url='https://www.horou.com/plugin.php?id=jnfarm&do=store&submit=true×tamp=&formhash=' + formhash + '&storesubmit=yes&prod[' + prod + ']=1&prodqty[' + prod + ']=' + prodqty
r=session.get(url,headers=headers)
if "u529f" in r.text:
return f",出售作物 {prodqty}"#出售成功
else:
return ""
#购买
def shop(formhash,seed,num):
url='https://www.horou.com/plugin.php?id=jnfarm&do=shop&submit=true×tamp=&formhash=' + formhash + '&shopsubmit=yes&jsid[' + seed + ']=1&qty[' + seed + ']=' + num
r=session.get(url,headers=headers)
if "u529f" in r.text:
return f",购买种子 {num}" #消费成功
else:
return ",河洛币不足"
#退出
def logout(formhash):
url='https://www.horou.com/member.php?mod=logging&action=logout&formhash='+formhash
r=session.get(url,headers=headers)
# pushplus微信推送
def pushplus_send(token,title,content):
token = token
title = title
content = content
url = f"https://www.pushplus.plus/send?token={token}&title={title}&content={content}"
response = requests.get(url=url)
print(response.text)
def main():
#用户名
username = "xxx"
#登录密码
password = "xxx"
#土地数量
jfid = "xxx"
#播种编号
prod = "xxx"
#推送
pushplus_token = "xxx"
pushplus_title = "xxx"
#keys = ["prod","name","seed"]
values = [["1","小麦","1"], ["2","胡萝卜","2"], ["3","玉米","5"],["4","土豆","6"],["5","花生","19"],["6","番茄","7"],["7","棉花","20"],["8","豌豆","8"]]
#dict_list =
#print(dict_list["seed"])
name = values #作物名称
seed = values #商店编号
fert_name = values
fert_seed = values
#定时触发器设置成长时间,若土地数量>仓库编号*1.5,将触发时间倍数缩小或设为体力恢复时间
(loginhash,formhash)=get_login_window()
msg_login = username + login(loginhash,formhash,username,password)
if '登录失败' in msg_login:
print(msg_login)
pushplus_send(pushplus_token,pushplus_title,msg_login)
return
formhash = get_formhash()
active = True
while active:
seedqty,prodqty,fertqty = store(prod)
msg_store = f"\n播种{name},仓库数量 {seedqty}"
msg_shop =""
numseed = int(jfid) - int(seedqty)
if numseed > 0:
msg_shop = shop(formhash,seed,str(numseed))
while(msg_shop == ",河洛币不足" and numseed > 1):
numseed -= 1
msg_shop = shop(formhash,seed,str(numseed))
msg_jnfarm =""
numjfid = 1
while(int(jfid) >= numjfid):
msg_harvest = harvest(formhash,str(numjfid))
msg_plantseed = plantseed(formhash,seed,str(numjfid))
msg_normal = ""
if msg_plantseed != "没有种子":
msg_normal = normal(formhash,str(numjfid))
msg_jnfarm = msg_jnfarm + msg_harvest + msg_plantseed + msg_normal
numjfid += 1
time.sleep(1)
#print(msg_jnfarm)
seedqty,prodqty,fertqty = store(prod)
msg_sold =""
if prodqty != "0":
msg_sold = sold(formhash,prod,prodqty)
if "没有种子" in msg_jnfarm and msg_sold != "":
active = True
else:
active = False
msg = msg_login + msg_jnfarm + msg_store + msg_shop + msg_sold + msg_fert
print(msg)
if int(prod)*3/2 < int(jfid) and "体力不足" in msg_jnfarm:
pushplus_send(pushplus_token,pushplus_title,msg)
if "成熟" not in msg_jnfarm:
pushplus_send(pushplus_token,pushplus_title,msg)
logout(formhash)
def handler(event, context):
main()
if __name__=="__main__":
main()
非常好的分享 梦回大学的农场偷菜时光 大神幸苦了,感谢分享 好久好久没去农场劳动了:lol 这个咋用? 涨姿势了,第一次知道论坛还可以玩农场
页:
[1]