根据用户的拥有鸭子数量,决定是否收取和卖出鸭子

主要用于探险鸡鸭类小程序,判断探险鸭是否在家,自动派出探险鸭,判断抓回的小鸭数量,决定是否卖掉鸭子,判断是否有孵化的小鸭,有的话卖掉鸭子

#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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值