蜀黍说不能太长 发表于 2021-12-27 23:48

鼓起勇气分享个今日头条极速版开心农场完成任务........

经过四处复制粘贴自己抄袭着弄了个农场任务...基本任务(签到/三餐礼包/浇水/领水滴/灭虫)能做完...能用...仅是能用的程度...只是代码就惨不忍睹了...不会变通..只是硬抄...
任务是放到青龙面板上定时运行的....定时是:0 1 7,11,18,19,20 * * *....
还有因为不会把值写到环境变量去...签到任务用到ttncqd.txt...如果真有人用要在同目录下建个ttncqd.txt,里面输入个1....{:301_1004:}

其实发上来是想看看有没路过的大佬有空闲优化优化顺便注释注释,自己感觉实在看不下去。{:301_1004:}
import requests
from time import sleep
import json
import datetime
import re
from difflib import *
import random

try:
    from notify import send
except:
    logger.info("无推送文件")

#头条种农作物
headers={}#抓自己的请求头



#头条1浇水签到,2签到翻倍
f=open('ttncqd.txt','r')
ncqd1=f.read()#取内容作为变量上次结果
f.close()
ncqd1=int(ncqd1)
urlqd1='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/reward/sign_in?game_client_version_code=2&watch_ad=0&extra_ads_num=0&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=true'
urlqd2='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/reward/double_sign_in?game_client_version_code=2&watch_ad=0&extra_ads_num=0&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=true'
while ncqd1==1:
    resqd1=requests.get(headers=headers,url=urlqd1,timeout=1).json()
    sleep(3)
    resqd1=requests.get(headers=headers,url=urlqd1,timeout=1).json()
    sleep(3)
    resqd2=requests.get(headers=headers,url=urlqd2,timeout=1).json()
    sleep(3)
    resqd2=requests.get(headers=headers,url=urlqd2,timeout=1).json()
    try:
      print("今天签到情况:"+resqd1['message'])
      print()
      ttqdqk1="今天签到情况:"+resqd1['message']+"今天翻倍情况:"+resqd2['message']
      ncqd1="0"
      f=open('ttncqd.txt','w')
      f.write(ncqd1)
      f.close()
    except:
      print("签到出现异常")
      ttqdqk1="当天签到任务出现异常!"
    continue
while ncqd1==0:
    print("当天签到任务已执行")
    ttqdqk1="当天签到任务已执行!"
    ncqd1=3
    continue


ttzzjg=ttqdqk1
#头条领水链接7点1次,11点1次,18点1次
jsurl1='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/reward/gift?game_client_version_code=2&gift_id=1&watch_ad=1&double=0&extra_ads_num=0&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=true'
jsurl2='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/reward/gift?game_client_version_code=2&gift_id=2&watch_ad=1&double=0&extra_ads_num=0&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=true'
jsurl3='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/reward/gift?game_client_version_code=2&gift_id=3&watch_ad=1&double=0&extra_ads_num=0&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=true'
urlzclq1=1
urlwulq1=1
urlwalq1=1


print("开始领取三餐礼包")
while urlzclq1<=1:
    time1 = datetime.datetime.now().strftime("%H:%M:%S.%f")
    # 判断时间
    if time1 >= '07:00:00' and time1 <= '09:00:00':# 开始时间7—9
      jsres1=requests.get(headers=headers,url=jsurl1,timeout=1).json()
      sleep(3)
      jsres1=requests.get(headers=headers,url=jsurl1,timeout=1).json()
      try:
            print("早餐礼包:"+jsres1['message'])
            scjg1="\n早餐礼包:"+jsres1['message']
            urlzclq1=urlzclq1+1
            sleep(1)
      except:
            print("早餐礼包:可能领取失败")
            scjg1="\n早餐礼包:可能领取失败"
            urlzclq1=urlzclq1+1
            sleep(1)
    else:
      urlzclq1=urlzclq1+1
      print("早餐礼包:时间范围不符合,任务不执行!")
      scjg1="\n早餐礼包:时间范围不符合,任务不执行!"
      continue

while urlwalq1<=1:
    time1 = datetime.datetime.now().strftime("%H:%M:%S.%f")
    # 判断时间
    if time1 >= '11:00:00' and time1 <= '14:00:00':# 开始时间11—14
      jsres2=requests.get(headers=headers,url=jsurl2,timeout=1).json()
      sleep(3)
      jsres2=requests.get(headers=headers,url=jsurl2,timeout=1).json()
      try:
            print("午餐礼包:"+jsres2['message'])
            scjg2="\n午餐礼包:"+jsres2['message']
            urlwalq1=urlwalq1+1
            sleep(1)
      except:
            print("午餐礼包:可能领取失败")
            scjg2="\n午餐礼包:可能领取失败"
            urlwalq1=urlwalq1+1
            sleep(1)
    else:
      urlwalq1=urlwalq1+1
      print("午餐礼包:时间范围不符合,任务跳过。")
      scjg2="\n午餐礼包:时间范围不符合,任务不执行!"
      continue


while urlwulq1<=1:
    time1 = datetime.datetime.now().strftime("%H:%M:%S.%f")
    # 判断时间
    if time1 >= '18:00:00' and time1 <= '21:00:00':# 开始时间18—21
      jsres3=requests.get(headers=headers,url=jsurl3,timeout=1).json()
      sleep(3)
      jsres3=requests.get(headers=headers,url=jsurl3,timeout=1).json()
      try:
            print("晚餐礼包:"+jsres3['message'])
            scjg3="\n晚餐礼包:"+jsres3['message']
            urlwulq1=urlwulq1+1
            sleep(1)
      except:
            print("晚餐礼包:可能领取失败")
            scjg3="\n晚餐礼包:可能领取失败"
            urlwulq1=urlwulq1+1
            sleep(1)
    else:
      urlwulq1=urlwulq1+1
      print("晚餐礼包:时间范围不符合,任务跳过!")
      scjg3="\n晚餐礼包:时间范围不符合,任务跳过!"
      continue


ttzzjg=ttqdqk1+scjg1+scjg2+scjg3


#头条1开宝箱,2翻倍,共可执行5次
urlbx1='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/box/open?game_client_version_code=2&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=true'
urlbx2='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/excitation_ad/add?game_client_version_code=2&excitation_ad_score_amount=134&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=true'
ttncbx=1
while ttncbx==1:
    bx1=requests.get(headers=headers,url=urlbx1,timeout=1).json()#领取
    sleep(3)
    bx2=requests.get(headers=headers,url=urlbx2,timeout=1).json()#翻倍
    sleep(3)
    bxjg1="\n宝箱领取积分:"+str(bx1['data']['incr_coin'])+";宝箱领取积分翻倍:"+str(bx2['data']['incr_coin'])
    print(bxjg1)
    ttncbx=ttncbx+1
    continue



ttzzjg=ttqdqk1+scjg1+scjg2+scjg3+bxjg1





#头条浇水链接
urljs1='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/land_water?game_client_version_code=2&tentimes=0&fivetimes=0&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=true'
sdslurl='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/enter?game_client_version_code=2&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=false'
sdsl=requests.get(headers=headers,url=sdslurl,timeout=1).json()
jscs1=sdsl['data']['water']
while jscs1>100:
    time1 = datetime.datetime.now().strftime("%H:%M:%S.%f")
    # 判断时间
    if time1 >= '20:00:00' and time1 <= '23:00:00':# 开始时间
      res=requests.get(headers=headers,url=urljs1,timeout=1).json()
      jscs2=11
      try:
            print("水滴剩余:"+str(res['data']['water']))
            js="\n已浇水10次,水滴剩余:"+str(res['data']['water'])
            sdsl=requests.get(headers=headers,url=sdslurl,timeout=1).json()
            jscs1=sdsl['data']['water']
            sleep(1)
            ncqd1="1"
            f=open('ttncqd.txt','w')
            f.write(ncqd1)
            f.close()
      except:
            print("水滴剩余:"+str(res['message']))
            js="\n已浇水10次,水滴剩余:"+str(res['message'])
            sdsl=requests.get(headers=headers,url=sdslurl,timeout=1).json()
            jscs1=sdsl['data']['water']
            sleep(1)
            ncqd1="1"
            f=open('ttncqd.txt','w')
            f.write(ncqd1)
            f.close()
    else:
      jscs1=0
      jscs2=0
      print("时间范围不符合")
      js="\n时间范围不符合暂不浇水!"
      continue


#头条浇水符合10次后领取链接
urljsrwlq1='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/reward/task?game_client_version_code=2&task_id=1&is_auto_reward=0&is_surprise_box_reward=0&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=false'
urljsrwlq2='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/reward/task?game_client_version_code=2&task_id=2&is_auto_reward=0&is_surprise_box_reward=0&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=false'
urljsrwlq3='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/reward/task?game_client_version_code=2&task_id=3&is_auto_reward=0&is_surprise_box_reward=0&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=false'
urljsrwlq4='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/reward/task?game_client_version_code=2&task_id=4&is_auto_reward=0&is_surprise_box_reward=0&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=false'
while jscs2==11:
    res1=requests.get(headers=headers,url=urljsrwlq1,timeout=1).json()
    sleep(1)
    res2=requests.get(headers=headers,url=urljsrwlq2,timeout=1).json()
    sleep(1)
    res3=requests.get(headers=headers,url=urljsrwlq3,timeout=1).json()
    sleep(1)
    res4=requests.get(headers=headers,url=urljsrwlq4,timeout=1).json()
    sleep(1)
    res1=requests.get(headers=headers,url=urljsrwlq1,timeout=1).json()
    sleep(1)
    res2=requests.get(headers=headers,url=urljsrwlq2,timeout=1).json()
    sleep(1)
    res3=requests.get(headers=headers,url=urljsrwlq3,timeout=1).json()
    sleep(1)
    res4=requests.get(headers=headers,url=urljsrwlq4,timeout=1).json()
    sleep(1)
    try:
      jsrwlqjg="\n1."+res1['message']+",2."+res2['message']+",3."+res3['message']+",4."+res4['message']
      sleep(1)
    except:
      jsrwlqjg="\n领取浇水后4个可能出错了"
    jscs2=jscs2+1
    continue
try:
    ttzzjg=ttqdqk1+scjg1+scjg2+scjg3+bxjg1+js+jsrwlqjg
except:
    ttzzjg=ttqdqk1+scjg1+scjg2+scjg3+bxjg1+js


#头条种农作物抓虫子
cookie='install_id=1487003035112286;ttreq=1$dfdad9b7e9cfb3a09c1d5b94654ae35ac41e577f;d_ticket=b85eba35f2c44055a45f6cf75a3c986822e4b;n_mh=CNk9YaZcAWuuh1L15mDzJsInswrl03GPjAgWSURK1jM;odin_tt=50b9623ed945f15e01265e62dd512144dbd5722297d501aab4690c704c7891437a272b1ee2a50ca5d081addff98b638b8115bf7ba2859b3deb115d11a4883e90;sessionid=50ac154122f8017821a2b128ee402591;sessionid_ss=50ac154122f8017821a2b128ee402591;sid_guard=50ac154122f8017821a2b128ee402591%7C1639840701%7C5184000%7CWed%2C+16-Feb-2022+15%3A18%3A21+GMT;sid_tt=50ac154122f8017821a2b128ee402591;uid_tt=5436a654febc867ef2308fb33a0e362c;uid_tt_ss=5436a654febc867ef2308fb33a0e362c;passport_csrf_token=8004047dbf09ef3a44985dafb2297e49;passport_csrf_token_default=8004047dbf09ef3a44985dafb2297e49;MONITOR_WEB_ID=7d6a399c-e1a1-4c11-adad-0dd1f487d5cc'
headers={"Accept-Encoding": "gzip, deflate","Connection": "close","Content-Type": "application/json","Cookie": cookie,"Host": "api3-normal-hl.toutiaoapi.com","Referer": "https://tmaservice.developer.toutiao.com/?appid=tta539d3843a134f3d&version=1.2.45","User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 NewsArticle/8.5.6.22 JsSdk/2.0 NetType/4G (NewsLite 8.5.6 14.300000) NewsLite/8.5.6 Mobile ToutiaoMicroApp/2.31.1.0","X-Argus": "DSQ9ksfC6XJEHn9uTVrqJxZpwqLvnGgkikJ2f7HXXMsxKvuL2YfT9Dn12Xm0ReHu3K0+xDG/zowOQRgVIeejVlWowBcBSGXjcIKaQu+R7fJ0UM5gUZDkMV5Le/ngcs0OH3NgPmnk9E0t9Yx6FnJB9rcflZR304aq3rcckR5roIQcfK4sL7eYlq3JVnH21krqi3Tz1VsXhYxKzW8tFE5Lqhnhu2mirzXFIl38OGoEW6wPIk6LcAcPktLwa+W4SJf8o+A=","X-Gorgon": "8404607e00006ae193d639b8e63bde2639d62e7142893dbea658","X-Khronos": "1639926091","X-Ladon": "g3K4HSBDWiEwxP3l0BY5coX5/uiRlzWGHH2LBLfoL4pYDBOK","X-SS-Cookie": "install_id=1487003035112286; ttreq=1$dfdad9b7e9cfb3a09c1d5b94654ae35ac41e577f; MONITOR_WEB_ID=7d6a399c-e1a1-4c11-adad-0dd1f487d5cc; d_ticket=b85eba35f2c44055a45f6cf75a3c986822e4b; n_mh=CNk9YaZcAWuuh1L15mDzJsInswrl03GPjAgWSURK1jM; odin_tt=50b9623ed945f15e01265e62dd512144dbd5722297d501aab4690c704c7891437a272b1ee2a50ca5d081addff98b638b8115bf7ba2859b3deb115d11a4883e90; sessionid=50ac154122f8017821a2b128ee402591; sessionid_ss=50ac154122f8017821a2b128ee402591; sid_guard=50ac154122f8017821a2b128ee402591%7C1639840701%7C5184000%7CWed%2C+16-Feb-2022+15%3A18%3A21+GMT; sid_tt=50ac154122f8017821a2b128ee402591; uid_tt=5436a654febc867ef2308fb33a0e362c; uid_tt_ss=5436a654febc867ef2308fb33a0e362c; passport_csrf_token=8004047dbf09ef3a44985dafb2297e49; passport_csrf_token_default=8004047dbf09ef3a44985dafb2297e49","X-SS-DP": "35","passport-sdk-version": "5.17.4-rc.11.6-bugfix","sdk-version": "2","tt-request-time": "1639926091585","x-Tt-Token": "0050ac154122f8017821a2b128ee40259103a7a698357fc9e7b2feb0f525890a4029223735f469058e38e534775f1d31b23d740003649850559fc2d41a79974c372c315bc3e261407fac9d9ccab7c56b7ea1af5cd0a41afcb87d3165e9d1b95d25aa9-1.0.1","x-tt-dt": "AAA3W7F3QHGHFKFVLAAD4TTS2B5RGP3JBTMI7T56DL5ZRONQ6FRUV2YUZEMDCJP36TPCJSQWKIKGRQG56SBONXW7QPZZSPNUGDILPNP7DFCLFDYNNMP3G2YXPLBEO63SZRU6K65ENSVCI5AEK6YNGRI","x-tt-store-region": "cn-gd","x-tt-store-region-src": "did","x-tt-trace-id": "00-d33650c00da8fa94ca82f6879d440023-d33650c00da8fa94-01","x-vc-bdturing-sdk-version": "2.2.7"}
pdczurl='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/home_info?game_client_version_code=2&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=false'
pdczzt=requests.get(headers=headers,url=pdczurl,timeout=1).json()
haichong1="害虫事件"
hcpd1=haichong1 in str(pdczzt)

if hcpd1==True:
    landid=1
    while landid<10:
      cdczurl1='https://api3-normal-hl.toutiaoapi.com/ttgame/game_farm/handle_event?game_client_version_code=2&land_id='+str(landid)+'&event_type=2&watch_ad=1&extra_ads_num=0&device_id=2972707065442152&device_platform=iphone&aid=35&os_version=14.3&update_version_code=85622&tma_jssdk_version=2.25.0.9&sid=&version_code=8.5.6&install_id=1487003035112286&app_name=news_article_lite&device_type=iPhone13,2&channel=App%20Store&host_app_name=undefined&activity_id=&credit_type=&use_tomato=0&ios_new_version=false'
      cz=requests.get(headers=headers,url=cdczurl1,timeout=1).json()
      landid=landid+1
      chongzizhuangtai="\n害虫事件:已除虫,"
      sleep(16)
      print("除虫")
      continue
else:
    print("没虫子")


try:
    ttzzjg=ttzzjg+chongzizhuangtai
except:
    sleep(1)


send('头条农场任务结果推送', ttzzjg)

benmagic 发表于 2021-12-28 09:12

美团的领水果的能写个嘛+1

52leitong2016 发表于 2021-12-28 09:10

大佬,美团的领水果的能写个嘛? 手动做任务太费时间了{:301_997:}

adf28 发表于 2021-12-28 01:10

谢谢分享,这个应该实用

cpnorg 发表于 2021-12-28 05:38

过来学习一下Python

不苦小和尚 发表于 2021-12-28 07:37

温习一下基础语法

T626 发表于 2021-12-28 08:03

感谢分享

Wapj_Wolf 发表于 2021-12-28 08:15

谢谢分享,学习PY中。

wubit 发表于 2021-12-28 09:05

headers怎么抓回来.

YR0207 发表于 2021-12-28 09:10

能用在云函数吗

逆劫古修 发表于 2021-12-28 09:11

努力学习中,谢谢分享
页: [1] 2 3
查看完整版本: 鼓起勇气分享个今日头条极速版开心农场完成任务........