吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1980|回复: 6
收起左侧

[Python 原创] Discuz!论坛农场脚本

[复制链接]
Velens 发表于 2023-12-8 00:38
本帖最后由 Velens 于 2023-12-8 00:55 编辑

功能介绍:
Discuz!论坛农场脚本,以某洛论坛为例,支持微信推送
等级不够,values没有放全,高等级请自行通过F12补充
自行修改headers和xxx参数,支持云。函数和openwrt挂载


脚本代码:
[Python] 纯文本查看 复制代码
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[p:p+5]
    #获取formhash
    p=r.text.find('formhash')+len('formhash" value="')
    formhash=r.text[p:p+8]
    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[p:p+8]
    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[p:p+10]
    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[p-18:p+11]
        seedqty = re.findall(r'="(.+?)"', value)[0]
    else:
        seedqty = "0"
    p=r.text.find(f"prodqty[{prod}]")
    if p != -1:
        value=r.text[p-18:p+11]
        prodqty = re.findall(r'="(.+?)"', value)[0]
    else:
        prodqty = "0"
    p=r.text.find(f"fertqty[1]")
    if p != -1:
        value=r.text[p-18:p+11]
        fertqty = re.findall(r'="(.+?)"', value)[0]
    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[p-20:p-9]
        tili = re.findall(r'\d+', value)[0]
    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 = [dict(zip(keys, value)) for value in values]
    #print(dict_list[2]["seed"])
    name = values[int(prod)-1][1]     #作物名称
    seed = values[int(prod)-1][2]     #商店编号
    fert_name = values[int(fert)-1][1]
    fert_seed = values[int(fert)-1][2]
    #定时触发器设置成长时间,若土地数量>仓库编号*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()

免费评分

参与人数 1吾爱币 +7 热心值 +1 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

ququ001 发表于 2023-12-8 06:42
非常好的分享
Corgibro 发表于 2023-12-8 07:43
Agri6789 发表于 2023-12-8 08:12
hu007 发表于 2023-12-8 09:14
好久好久没去农场劳动了
坐久落花多 发表于 2023-12-8 09:19
这个咋用?
bohong65 发表于 2023-12-8 10:08
涨姿势了,第一次知道论坛还可以玩农场
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 16:15

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表