主要用于探险鸡鸭类小程序,判断探险鸭是否在家,自动派出探险鸭,判断抓回的小鸭数量,决定是否卖掉鸭子,判断是否有孵化的小鸭,有的话卖掉鸭子
#author = lixj
#date = 19.4.14
#主要用来跑小程序,根据当前用户拥有小鸭数量决定是否卖出,根据探险鸡是否回来让探险鸭自动探险
import requests
import time
import json
import jsonpath
token = 'a45f2e642225f98f9cd064990e30b463'
header = {'charset': 'utf-8','Accept-Encoding': 'gzip','referer': 'https://servicewechat.com/wx422986e0fce6808e/12/page-frame.html','content-type': 'application/json','User-Agent': 'Mozilla/5.0 (Linux; Android 8.0.0; MI 6 Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MicroMessenger/7.0.3.1400(0x2700033D) Process/appbrand0 NetType/WIFI Language/zh_CN','Content-Length': '44','Host': 'ddy.xiaotaotao123.cn','Connection': 'Keep-Alive'
}
data = {"token":token}
#请求探险鸭首页接口
def post_xiaoji():
post_xiaoji_url = 'https://ddy.xiaotaotao123.cn/api/chicken/getChickenPage'
post_xiaoji_go = requests.post(post_xiaoji_url,data = json.dumps(data) ,headers = header)
print(post_xiaoji_go.text)
return post_xiaoji_go.text
#请求鸭蛋接口
def post_yadan():
post_yadan_url = 'https://ddy.xiaotaotao123.cn/api/chicken/getEggPage'
post_yadan_go = requests.post(post_yadan_url, data=json.dumps(data), headers=header)
print(post_yadan_go.text)
return post_yadan_go.text
#判断小鸭数量是否大于0,如果大于0,则出售小鸭
def sell_xiaoji():
post_sell_url = 'https://ddy.xiaotaotao123.cn/api/chicken/sellXiaoji'
post_tanxianji_url = 'https://ddy.xiaotaotao123.cn/api/chicken/sendChicken'
try:
text = post_xiaoji()
json_xiaoji = json.loads(text)
xiaoji_number = jsonpath.jsonpath(json_xiaoji, expr='$..xiaoji')
tanxianji_number = jsonpath.jsonpath(json_xiaoji, expr='$..auto_time')
tanxianji_auto_number = jsonpath.jsonpath(json_xiaoji, expr='$..xiaoji_time')
# 判断小鸡数量是否大于0
try:
number = xiaoji_number[0]
if number > 0:
post_sell_xiaoji = requests.post(post_sell_url, data=json.dumps(data), headers=header)
print(post_sell_xiaoji.text)
else:
print('小鸡数量不足,不能售卖')
except:
print('没有获取到小鸭数量')
# 计算探险鸭是否在家,根据探险鸭上次出发时间和自动探险时间
try:
tanxianji_back_time = tanxianji_auto_number[0] + tanxianji_number[0] * 60 * 60
new_time = time.time()
if new_time > tanxianji_back_time:
post_tanxianji_go = requests.post(post_tanxianji_url, data=json.dumps(data), headers=header)
print(post_tanxianji_go.text)
else:
print('探险鸭还没有回家哦!')
except:
print('没有计算出探险鸭是否在家')
except:
print('请求探险鸭接口失败')
# 判断是否有孵化好的鸭蛋
def collect_yadan():
collect_yadan_url = 'https://ddy.xiaotaotao123.cn/api/chicken/collectEggChicken'
sell_yazi_url = 'https://ddy.xiaotaotao123.cn/api/chicken/sellEggChicken'
text = post_yadan()
json_yadan = json.loads(text)
yadan_number = jsonpath.jsonpath(json_yadan, expr='$..jizai')
try:
number = int(yadan_number[0])
if number > 0:
post_collect_yadan = requests.post(collect_yadan_url, data=json.dumps(data), headers=header)
print('鸭蛋数量'+ string(post_collect_yadan.text))
sell_yazi_go = requests.post(sell_yazi_url, data=json.dumps(data), headers=header)
print('售出鸭蛋数量' + string(sell_yazi_go.text))
else:
print('鸭蛋数量不足,不能收集')
except:
print('没有获取到鸭蛋数量')
if __name__ == '__main__':
for x in range(10000):
sell_xiaoji()
collect_yadan()
print('*****************************************************************************************************************************')
x = x + 1
time.sleep(300)