Python数据分析的过程记录(六)
一、需求分析
①数字1的位置为下期要买小的位置 ,如果中了,下期继续买中的当期1的新位置
②数字1的位置下期开奖没有中,那下期就买数字2(③)位置的小,如果数字2下期中了就继续买数字2的新位置,数字2位置没中,下期就买数字3的位置,数字3没中就买数字4,数字4没中就买数字5,数字5没中就重新从数字1开始,1-2-3-4-5-1,以此循环买
二、代码:
import requests
import re
import json
import xlwt
TOTAL = 1151
wb = xlwt.Workbook()
# 创建 excel 表格
sh = wb.add_sheet('彩票分析数据处理')
# 创建一个 表单
sh.write(0, 0, "日期")
sh.write(0, 1, "购买数目")
sh.write(0, 2, "命中数目")
sh.write(0, 3, "挂的数目")
sh.write(0, 4, "6次中的数目")
sh.write(0, 5, "6次中的时间")
sh.write(0, 6, "7次中的数目")
sh.write(0, 7, "7次中的时间")
sh.write(0, 8, "8次中的数目")
sh.write(0, 9, "8次中的时间")
sh.write(0, 10, "9次中的数目")
sh.write(0, 11, "9次中的时间")
sh.write(0, 12, "10次中的数目")
sh.write(0, 13, "10次中的时间")
sh.write(0, 14, "11次中的数目")
sh.write(0, 15, "11次中的时间")
sh.write(0, 16, "12次中的数目")
sh.write(0, 17, "12次中的时间")
sh.write(0, 18, "13次中的数目")
sh.write(0, 19, "13次中的时间")
sh.write(0, 20, "14次中的数目")
sh.write(0, 21, "14次中的时间")
# wb.save('test1.xls')
list_of_the_dates = []
for i in range(31):
list_of_the_dates.append(f"7-{i + 1}")
list_of_the_dates.append("8-01")
list_of_the_dates.append("8-02")
excel_n = 1
for date in list_of_the_dates:
url = f'https:///pks/getPksHistoryList.do?lotCode=10037&date=2021-0{date}'
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36 Edg/92.0.902.62'
}
res = requests.get(url, headers=headers)
# print(res.content.decode())
new_res = json.loads(res.content.decode())["result"]["data"]
sh.write(excel_n, 0, new_res[0]["preDrawTime"][:10])
times_dict = {}
time_times_dict = {}
list_of_number = ["01", "02", "03", "04", "05"]
ln = 0
success_n = 0
times_n = 1
for i in range(1152):
n1 = 1151 - i
n2 = 1151 - i - 1
res_1 = new_res[n1]["preDrawCode"].split(",")
res_2 = new_res[n2]["preDrawCode"].split(",")
# index !!!
position_of_buy = res_1.index(list_of_number[ln])
# index!!
# res 1 index -- list_of_number[ln]
if res_2[position_of_buy] in list_of_number:
# success
# ln will not change !!
success_n += 1
if f"{times_n}" in time_times_dict.keys():
time_times_dict[f"{times_n}"].append(new_res[n2]["preDrawTime"][11:])
times_dict[f"{times_n}"] += 1 # ++
else:
time_times_dict[f"{times_n}"] = [new_res[n2]["preDrawTime"][11:]]
times_dict[f"{times_n}"] = 1 # 1
times_n = 1 # initial again !!!
# 1
# pass
else:
times_n += 1
# times_n += 1
# change !!
ln = (ln + 1) % 5
# change
# avoid to up error
sh.write(excel_n, 1, 1151)
print(success_n)
sh.write(excel_n, 2, success_n)
sh.write(excel_n, 3, TOTAL - success_n)
print(TOTAL - success_n)
for jn in times_dict.keys():
if int(jn) >= 6:
print("times: " + str(times_dict[jn]))
sh.write(excel_n, 4 + 2 * (int(jn) - 6), times_dict[jn])
print("time of times: " + str(time_times_dict[jn]))
sh.write(excel_n, 5 + 2 * (int(jn) - 6), time_times_dict[jn])
excel_n += 1
wb.save("极速赛车-分析结果.xls")