fix: 修改代码逻辑

This commit is contained in:
chenwj113 2023-04-29 18:49:50 +08:00
parent 9655da0df7
commit 6e17470823
5 changed files with 67 additions and 40 deletions

View File

@ -14,6 +14,7 @@ def _get_data(url, lottery_type):
draw_issue = table_list.find("td.td_title01 span.span_left strong")[0].text
draw_date = table_list.find("td.td_title01 span.span_right")[0].text
draw_code = table_list.find("div.ball_box01")[0].text.replace('\n', '')
print(draw_code)
last_id = lottery.insert(draw_issue, draw_date, draw_code)
if last_id:
print(f"issue:{draw_issue}数据写入完成。。。")
@ -25,6 +26,7 @@ def get_data(url, lottery_type):
_get_data(url, lottery_type)
except Exception as e:
print(e)
print(url)
print('异常出错重试后,依然报错')
raise e
@ -42,16 +44,15 @@ def main(basic_url, lottery_type):
continue
if __name__ == '__main__':
url = "https://kaijiang.500.com/shtml/pls/22265.shtml"
# url = "https://kaijiang.500.com/shtml/sd/04001.shtml"
# url = "https://kaijiang.500.com/shtml/plw/04001.shtml"
# main(url, lottery_type='plw')
for y in range(24, 25):
for i in range(1, 365):
try :
issue = str(y) + f"{i:03d}"
issue = "23107"
url = f"https://kaijiang.500.com/shtml/pls/{issue}.shtml"
get_data(url, lottery_type='pls')
except Exception as e:
print(e)
break
# for y in range(23, 24):
# for i in range(1, 365):
# try :
# issue = f"{y:02d}{i:03d}"
# url = f"https://kaijiang.500.com/shtml/plw/{issue}.shtml"
# get_data(url, lottery_type='plw')
# except Exception as e:
# print(e)
# continue

View File

@ -49,16 +49,17 @@ class Lottery(object):
else:
raise Exception(f"issue:{draw_issue}数据写入失败。。。")
# 如果是排列3和3D
if isinstance(record, PLS) or isinstance(record, SD):
record.hundred = draw_code[0]
record.ten = draw_code[1]
record.one = draw_code[2]
if isinstance(record, PLS) or isinstance(record, SD) or isinstance(record, PLW):
record.draw_code = draw_code
record.sum_num = sum(map(int, draw_code))
record.code_small = len(list(filter(lambda x: True if int(x) < 5 else False, draw_code)))
record.code_big = len(list(filter(lambda x: True if int(x) >= 5 else False, draw_code)))
record.code_single = len(list(filter(lambda x: True if int(x) % 2 == 1 else False, draw_code)))
record.code_double = len(list(filter(lambda x: True if int(x) % 2 == 0 else False, draw_code)))
record.draw_code = draw_code
record.sum_num = sum(map(int, draw_code))
if isinstance(record, PLS) or isinstance(record, SD):
record.hundred = draw_code[0]
record.ten = draw_code[1]
record.one = draw_code[2]
record.sum_hundred_one = int(draw_code[2]) + int(draw_code[0])
record.sum_hundred_ten = int(draw_code[2]) + int(record.draw_code[1])
record.sum_ten_one = int(record.draw_code[1]) + int(record.draw_code[0])
@ -68,6 +69,15 @@ class Lottery(object):
record.group_type = 6
else:
record.group_type = 1
elif isinstance(record, PLW):
record.ten_thousand = draw_code[0]
record.thousand = draw_code[1]
record.hundred = draw_code[2]
record.ten = draw_code[3]
record.one = draw_code[4]
record.sum_hundred_one = int(draw_code[2]) + int(draw_code[4])
record.sum_hundred_ten = int(draw_code[2]) + int(record.draw_code[3])
record.sum_ten_one = int(record.draw_code[3]) + int(record.draw_code[4])
self.db.add(record)
self.db.commit()
return record.id

View File

@ -1,5 +1,5 @@
# coding: utf-8
from sqlalchemy import Column, Date, Integer, String
from sqlalchemy import Column, Date, Integer, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
@ -27,3 +27,4 @@ class PLS(Base):
sum_hundred_one = Column(Integer, comment='百位各位和')
sum_single_double = Column(Integer, comment='总和奇偶')
sum_big_small = Column(Integer, comment='总和大小')
created_at = Column(DateTime)

View File

@ -13,6 +13,11 @@ class PLW(Base):
draw_issue = Column(String(25, 'utf8mb4_general_ci'))
draw_date = Column(Date)
draw_code = Column(String(10, 'utf8mb4_general_ci'))
ten_thousand = Column(Integer)
thousand = Column(Integer)
hundred = Column(Integer)
ten = Column(Integer)
one = Column(Integer)
code_big = Column(Integer)
code_small = Column(Integer)
code_single = Column(Integer)

32
pls.py
View File

@ -5,6 +5,15 @@ import pandas as pd
a = np.arange(1000)
l = set([ "".join(sorted(f"{i:03d}")) for i in a ])
f1 = lambda number: True if '4' in number or '7' in number else False
f2 = lambda number: True if sum(map(int, number)) in [10,12, 13, 14, 16, 17] else False
arr1 = list(filter(f1, l))
print(len(arr1))
print(arr1)
arr2 = list(filter(f2, arr1))
print(len(arr2))
print(arr2)
sum_list = [ sum(map(int, list(i))) for i in l]
sum_df = pd.value_counts(sum_list)
@ -36,17 +45,17 @@ for i in sum_group6_dict.keys():
f2 = lambda number: len([i for i in number if int(i) %2 == 1]) != 0
f3 = lambda n: True if int(n[1]) - int(n[0]) == 1 or int(n[2]) - int(n[1]) == 1 else False
f4 = lambda number: True if 'a' not in number else False
f5 = lambda number: True if '2' in number or '8' in number else False
f5 = lambda number: True if '5' in number or '1' in number or '9' in number else False
f6 = lambda number: True if len(set('279').difference(number)) == 2 else False
if i in [12,14, 15, 16, 17]:
# result = sum_group6_dict[i] + sum_group3_dict[i]
result = sum_group3_dict[i]
print("-"*15 + "组三" + "-"*15)
print(i, list(filter(f5, result)))
result = sum_group6_dict[i]
print("-"*15 + "组六" + "-"*15)
print(i, list(filter(f5, result)))
print()
# if i in [12, 14, 15, 16, 17]:
# # result = sum_group6_dict[i] + sum_group3_dict[i]
# result = sum_group3_dict[i]
# print("-"*15 + "组三" + "-"*15)
# print(i, list(filter(f5, result)))
# result = sum_group6_dict[i]
# print("-"*15 + "组六" + "-"*15)
# print(i, list(filter(f5, result)))
# print()
# 连号
@ -61,8 +70,9 @@ for i in a:
if int(item_2[0]) > 4 and int(item_2[1]) > 4 and int(item_2[2]) <= 4:
result_2.append(i)
f = lambda number: True if '6' in f"{number:03d}" else False
f = lambda number: True if '5' in f"{number:03d}" or '1' in f"{number:03d}" or '9' in f"{number:03d}" else False
arr = set([ "".join(sorted(f"{i:03d}")) for i in filter(f, result_1)])
# print(list(arr))
# print(len(result_1))
# print(len(arr))
# print(len(result_2))
# print(result_2[:20])