fix: 增加获取胜负彩数据模块
This commit is contained in:
parent
8ac58d4f24
commit
d67e21c033
100
get_data.py
100
get_data.py
|
|
@ -1,7 +1,6 @@
|
|||
from requests_html import HTML, HTMLSession
|
||||
from retrying import retry
|
||||
|
||||
|
||||
from lottery import Lottery
|
||||
|
||||
session = HTMLSession()
|
||||
|
|
@ -29,29 +28,84 @@ def get_data(url, lottery_type):
|
|||
print('异常出错重试后,依然报错')
|
||||
raise e
|
||||
|
||||
def main(basic_url, lottery_type):
|
||||
"""爬取相关数据"""
|
||||
r = session.get(basic_url)
|
||||
select_list = list(reversed(r.html.find('div.kjxq_box02_title_right span div a')))
|
||||
for item in select_list:
|
||||
html = HTML(html=item.html)
|
||||
url = html.find('a', first=True).attrs['href']
|
||||
|
||||
|
||||
class DataGetter(object):
|
||||
|
||||
def __init__(self):
|
||||
self.session = HTMLSession()
|
||||
|
||||
def _get_data(self, issue, lottery_type='pls'):
|
||||
"""
|
||||
"""
|
||||
r = self.session.get(f"https://kaijiang.500.com/shtml/{lottery_type}/{issue}.shtml")
|
||||
if lottery_type == 'sfc':
|
||||
# 开奖期数
|
||||
issue_elem = r.html.search('胜负彩(任九) 第 {} 期')
|
||||
draw_issue = HTML(html=issue_elem[0]).text
|
||||
# 胜负彩销量
|
||||
sfc_sale_elem = r.html.search('本期胜负彩销量:{}元')
|
||||
sfc_sale = HTML(html=sfc_sale_elem[0]).text.replace(",", "")
|
||||
# 任九销量
|
||||
rj_sale_elem = r.html.search('本期任九销量:{}元')
|
||||
rj_sale = HTML(html=rj_sale_elem[0]).text.replace(",", "")
|
||||
# 开奖结果
|
||||
table_list = r.html.find("table.kj_tablelist02", first=True)
|
||||
draw_code = table_list.find("tr")[2].text.replace('\n', ' ')
|
||||
# 开奖日期
|
||||
draw_date = table_list.find("td.td_title01 span.span_right")[0].text
|
||||
# 中奖详情
|
||||
table_list_02 = r.html.find("table.kj_tablelist02")[1]
|
||||
award_1_elem = table_list_02.find("tr")[2]
|
||||
award_2_elem = table_list_02.find("tr")[3]
|
||||
rj_award_elem = table_list_02.find("tr")[4]
|
||||
award_1_num = award_1_elem.find("td")[1].text.replace(",", "")
|
||||
award_1_money = award_1_elem.find("td")[2].text.replace(",", "")
|
||||
award_2_num = award_2_elem.find("td")[1].text.replace(",", "")
|
||||
award_2_money = award_2_elem.find("td")[2].text.replace(",", "")
|
||||
r9_award_num = rj_award_elem.find("td")[1].text.replace(",", "")
|
||||
r9_award_money = rj_award_elem.find("td")[2].text.replace(",", "")
|
||||
with Lottery(lottery_type='sfc') as lottery:
|
||||
last_id = lottery.insert(draw_issue, draw_date, draw_code, sfc_sale=sfc_sale, rj_sale=rj_sale,
|
||||
award_1_num=award_1_num, award_1_money=award_1_money, award_2_num=award_2_num, award_2_money=award_2_money, r9_award_num=r9_award_num, r9_award_money=r9_award_money)
|
||||
if last_id:
|
||||
print(f"issue:{draw_issue}数据写入完成。。。")
|
||||
else:
|
||||
print(f'issue:{draw_issue}已经存在')
|
||||
else:
|
||||
|
||||
table_list = r.html.find("table.kj_tablelist02", first=True)
|
||||
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', '')
|
||||
with Lottery(lottery_type=lottery_type) as lottery:
|
||||
last_id = lottery.insert(draw_issue, draw_date, draw_code)
|
||||
if last_id:
|
||||
print(f"issue:{draw_issue}数据写入完成。。。")
|
||||
else:
|
||||
print(f'issue:{draw_issue}已经存在')
|
||||
|
||||
def pls(self, issue):
|
||||
return self._get_data(issue, lottery_type='pls')
|
||||
|
||||
def plw(self, issue):
|
||||
return self._get_data(issue, lottery_type='plw')
|
||||
|
||||
def sd(self, issue):
|
||||
return self._get_data(issue, lottery_type='sd')
|
||||
|
||||
def sfc(self, issue):
|
||||
return self._get_data(issue, lottery_type='sfc')
|
||||
|
||||
if __name__ == '__main__':
|
||||
# issue = "23108"
|
||||
# url = f"https://kaijiang.500.com/shtml/pls/{issue}.shtml"
|
||||
# get_data(url, lottery_type='pls')
|
||||
getter = DataGetter()
|
||||
for i in range(1, 64):
|
||||
try :
|
||||
get_data(url, lottery_type)
|
||||
issue = f"{23}{i:03d}"
|
||||
getter.sfc(issue=issue)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
continue
|
||||
|
||||
if __name__ == '__main__':
|
||||
issue = "23108"
|
||||
url = f"https://kaijiang.500.com/shtml/pls/{issue}.shtml"
|
||||
get_data(url, lottery_type='pls')
|
||||
# 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
|
||||
|
|
@ -7,6 +7,7 @@ from model.pls import PLS
|
|||
from model.plw import PLW
|
||||
from model.sd import SD
|
||||
from model.klb import KLB
|
||||
from model.football_sfc import FootballSfc
|
||||
|
||||
class Lottery(object):
|
||||
"""
|
||||
|
|
@ -23,6 +24,8 @@ class Lottery(object):
|
|||
self._Model = SD
|
||||
elif lottery_type.lower() == 'plw':
|
||||
self._Model = PLW
|
||||
elif lottery_type.lower() == 'sfc':
|
||||
self._Model = FootballSfc
|
||||
elif lottery_type.lower() == 'klb':
|
||||
self._Model = KLB
|
||||
else:
|
||||
|
|
@ -37,9 +40,14 @@ class Lottery(object):
|
|||
return self
|
||||
|
||||
def __exit__(self, type, value, trace):
|
||||
print("close the db session...")
|
||||
self.db.close()
|
||||
|
||||
|
||||
def insert(self, draw_issue, draw_date, draw_code, **kwargs):
|
||||
"""
|
||||
插入3d、排列三、排列五
|
||||
"""
|
||||
result = self.db.query(self._Model).filter_by(draw_issue=draw_issue).first()
|
||||
if result is None:
|
||||
record = self._Model()
|
||||
|
|
@ -55,15 +63,14 @@ class Lottery(object):
|
|||
record.draw_date = date(int(m2.group(1)), int(m2.group(2)), int(m2.group(3)))
|
||||
else:
|
||||
raise Exception(f"issue:{draw_issue}数据写入失败。。。")
|
||||
# 如果是排列3和3D
|
||||
if isinstance(record, PLS) or isinstance(record, SD) or isinstance(record, PLW):
|
||||
record.draw_code = draw_code
|
||||
# 如果是排列五、排列五和3D
|
||||
if isinstance(record, (PLS, SD, PLW)):
|
||||
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)))
|
||||
if isinstance(record, PLS) or isinstance(record, SD):
|
||||
if isinstance(record, (PLS, SD)):
|
||||
record.hundred = draw_code[0]
|
||||
record.ten = draw_code[1]
|
||||
record.one = draw_code[2]
|
||||
|
|
@ -85,8 +92,19 @@ class Lottery(object):
|
|||
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])
|
||||
elif isinstance(record, FootballSfc):
|
||||
record.open_result = draw_code
|
||||
record.sale_money = kwargs["sfc_sale"]
|
||||
record.r9_sale_money = kwargs["rj_sale"]
|
||||
record.award_1_money = kwargs["award_1_money"]
|
||||
record.award_1_num = kwargs["award_1_num"]
|
||||
record.award_2_money = kwargs["award_2_money"]
|
||||
record.award_2_num = kwargs["award_2_num"]
|
||||
record.r9_award_money = kwargs["r9_award_money"]
|
||||
record.r9_award_num = kwargs["r9_award_num"]
|
||||
self.db.add(record)
|
||||
self.db.commit()
|
||||
return record.id
|
||||
else:
|
||||
print(f"{draw_issue}开奖结果已经写入数据库中...")
|
||||
return None
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
|
||||
class Foootball(object):
|
||||
def __init__(self):
|
||||
self.db = self._get_db_session()
|
||||
|
||||
def _get_db_session(self):
|
||||
_engine = create_engine("mysql+pymysql://test:123456@localhost/lottery?charset=utf8", pool_pre_ping=True, pool_recycle=3600)
|
||||
_DbSession = sessionmaker(bind=_engine)
|
||||
return _DbSession()
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, trace):
|
||||
self.db.close()
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
import arrow
|
||||
import requests_html
|
||||
import furl
|
||||
import time
|
||||
|
||||
class Game14(object):
|
||||
_open_url = "https://webapi.sporttery.cn/gateway/lottery/getFootBallDrawInfoByDrawNumV1.qry"
|
||||
|
||||
def __init__(self, issue, lottery_type="sfc14c"):
|
||||
self._issue = issue
|
||||
self._lottery_type = lottery_type
|
||||
self._now = arrow.now().format("YYYY-MM-DD HH:mm:ss")
|
||||
self._session = requests_html.HTMLSession()
|
||||
self._data = self._get_data()
|
||||
|
||||
def _get_data(self):
|
||||
# d1 = dict(v=int(time.time()*1000), lotteryType=self._lottery_type, issue=self._issue)
|
||||
# print(d1)
|
||||
d = dict(isVerify=1, lotteryGameNum=90, lotteryDrawNum=self._issue)
|
||||
r = self._session.get(furl.furl(self._open_url).add(d))
|
||||
print(r.json())
|
||||
# match_list_1 = r1.json()["result"]["matchList"]
|
||||
match_list = r.json()["value"]["matchList"]
|
||||
data = list()
|
||||
for idx, m in enumerate(match_list):
|
||||
m["finalScore"] = match_list_2[idx]["czScore"]
|
||||
m["result"] = match_list_2[idx]["result"]
|
||||
data.append(m)
|
||||
return data
|
||||
|
||||
def get_odds(self):
|
||||
odds = list()
|
||||
for m in self._data:
|
||||
o = dict()
|
||||
o["issue"] = m["issue"]
|
||||
o["match_no"] = m["matchId"]
|
||||
o["fix_id"] = m["dataXiUrl"]
|
||||
o["match_datetime"] = "20{0}-{1}".format(m["issue"][:2], m["matchTime"])
|
||||
o["host_name"] = m["homeTeam"]
|
||||
o["away_name"] = m["awaryTeam"]
|
||||
o["score"] = m["finalScore"] or "-:-"
|
||||
o["result"] = m["result"].replace("*", "-")
|
||||
o["win"] = float(m["winRate"])
|
||||
o["draw"] = float(m["deuceRate"])
|
||||
o["lost"] = float(m["loseRate"])
|
||||
o["create_time"] = self._now
|
||||
odds.append(o)
|
||||
return odds
|
||||
|
||||
def print_data(self):
|
||||
fix_ids = []
|
||||
for i in self._data:
|
||||
fix_ids.append(i["dataXiUrl"])
|
||||
print(fix_ids)
|
||||
|
||||
def main():
|
||||
obj = AicaiGame14("23060")
|
||||
obj.print_data()
|
||||
odds = obj.get_odds()
|
||||
for i in odds:
|
||||
print(i)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -44,10 +44,10 @@ for i in sum_group6_dict.keys():
|
|||
f1 = lambda number: len([i for i in number if int(i) %2 == 0]) != 0
|
||||
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 '3' not in number else False
|
||||
f5 = lambda number: True if '0' in number or '3' in number else False
|
||||
f4 = lambda number: True if '4' not in number and '6' not in number else False
|
||||
f5 = lambda number: True if '2' in number or '5' in number or '7' in number else False
|
||||
f6 = lambda number: True if len(set('279').difference(number)) == 2 else False
|
||||
if i in [13, 14, 15, 16, 17]:
|
||||
if i in [12, 13, 14, 15, 16, 17]:
|
||||
# result = sum_group6_dict[i] + sum_group3_dict[i]
|
||||
result = sum_group3_dict[i]
|
||||
print("-"*15 + "组三" + "-"*15)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
# coding: utf-8
|
||||
from sqlalchemy import Column, DateTime, Float, Integer, text
|
||||
from sqlalchemy.dialects.mysql import VARCHAR
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
Base = declarative_base()
|
||||
metadata = Base.metadata
|
||||
|
||||
|
||||
class FootballSfc(Base):
|
||||
__tablename__ = 'football_sfc_2023'
|
||||
__table_args__ = {'comment': '足彩胜负彩/任选九表'}
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
draw_issue = Column(VARCHAR(10), comment='期数')
|
||||
draw_date = Column(DateTime, comment='开奖时间')
|
||||
draw_code = Column(VARCHAR(50), comment='开奖结果')
|
||||
sale_money = Column(Integer, comment='胜负彩销售额')
|
||||
award_1_money = Column(Float(10), comment='一等奖单注奖金')
|
||||
award_1_num = Column(Integer, comment='一等奖中奖数')
|
||||
award_2_money = Column(Float(10), comment='二等奖单注奖金')
|
||||
award_2_num = Column(Integer, comment='二等奖中奖数')
|
||||
r9_sale_money = Column(Integer, comment='任九销售额')
|
||||
r9_award_money = Column(Float(10), comment='任九奖金')
|
||||
r9_award_num = Column(Integer, comment='任九中奖数')
|
||||
created_at = Column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# coding: utf-8
|
||||
from sqlalchemy import Column, Date, Integer
|
||||
from sqlalchemy import Column, Date, DateTime, Integer
|
||||
from sqlalchemy.dialects.mysql import VARCHAR
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
|
|
@ -9,6 +9,7 @@ metadata = Base.metadata
|
|||
|
||||
class SD(Base):
|
||||
__tablename__ = 'sd'
|
||||
__table_args__ = {'comment': '福彩3d统计表'}
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
draw_issue = Column(VARCHAR(25))
|
||||
|
|
@ -28,3 +29,4 @@ class SD(Base):
|
|||
sum_hundred_one = Column(Integer, comment='百位各位和')
|
||||
sum_single_double = Column(Integer, comment='总和奇偶')
|
||||
sum_big_small = Column(Integer, comment='总和大小')
|
||||
created_at = Column(DateTime)
|
||||
|
|
|
|||
|
|
@ -37,15 +37,15 @@ def get_data_job(lottery_type='pls'):
|
|||
print(f'issue:{draw_issue}已经存在')
|
||||
|
||||
|
||||
@repeat(every().day.at("00:01"))
|
||||
@repeat(every().day.at("18:01"))
|
||||
def pls_job():
|
||||
get_data_job(lottery_type='pls')
|
||||
|
||||
@repeat(every().day.at("00:02"))
|
||||
@repeat(every().day.at("18:02"))
|
||||
def plw_job():
|
||||
get_data_job(lottery_type='plw')
|
||||
|
||||
@repeat(every().day.at("00:03"))
|
||||
@repeat(every().day.at("18:03"))
|
||||
def sd_job():
|
||||
get_data_job(lottery_type='sd')
|
||||
|
||||
|
|
|
|||
|
|
@ -259,8 +259,8 @@ class Chrome(object):
|
|||
with Chrome() as chrome:
|
||||
# chrome.balance()
|
||||
# 组选
|
||||
result = ['059', '158', '167', '058', '067', '049', '256', '247', '148', '458', '269', '089', '278', '467', '069', '168', '249', '267', '258', '078']
|
||||
chrome.pls(result = result, multiple=2)
|
||||
result = ['058', '157', '238', '139', '278', '359', '089', '179', '138', '057']
|
||||
chrome.pls(result = result, multiple=1)
|
||||
# 直选
|
||||
# result = ['246', '264', '291', '219', '169']
|
||||
# chrome.pls(result=result, is_group=False)
|
||||
Loading…
Reference in New Issue