diff --git a/example/sql.py b/example/sql.py new file mode 100644 index 0000000..482b4cf --- /dev/null +++ b/example/sql.py @@ -0,0 +1,2 @@ +sql1 = """ +""" \ No newline at end of file diff --git a/lottery/__init__.py b/lottery/__init__.py index 37808eb..5794335 100644 --- a/lottery/__init__.py +++ b/lottery/__init__.py @@ -43,6 +43,15 @@ class Lottery(object): print("close the db session...") self.db.close() + def get_last_id_by_sum_num(self, sum_num): + """ + 根据总和获取id + """ + last_id = self.db.query(self._Model.id).filter_by(sum_num=sum_num).order_by(self._Model.id.desc()).first() + if last_id is not None: + return last_id[0] + return None + def insert(self, draw_issue, draw_date, draw_code, **kwargs): """ diff --git a/lottery/football/jcbf.py b/lottery/football/jcbf.py deleted file mode 100644 index 10f3e8c..0000000 --- a/lottery/football/jcbf.py +++ /dev/null @@ -1,23 +0,0 @@ -import requests -from furl import furl -import time -import json - -file = open("data.json", "w+") - -base_url = "https://www.ttyingqiu.com/" -f = furl(base_url) - -f.path = "/static/no_cache/league/zc/jsbf/ttyq2020/jsbf_2022-11-06.json" -f.args["v"] = int(time.time()*1000) -print(f.url) -print(r.status_code) -print(r.json()) -file.write(json.dumps(r.json())) -file.close() - - -url = "/static/no_cache/league/zc/jsbf/ttyq2020/jczq/jsbf_2022-11-06.json?v=1667799791084" -url = "https://www.ttyingqiu.com/static/no_cache/league/zc/jsbf/ttyq2020/jczq/2022-11-06/oz_407_6.json?v=1667799791169" - -match_list = data["matchList"] \ No newline at end of file diff --git a/lottery/football/jczq.py b/lottery/football/jczq.py index 88f38f0..506a78a 100644 --- a/lottery/football/jczq.py +++ b/lottery/football/jczq.py @@ -1,65 +1,98 @@ import sys sys.path.append("/root/documents/py_scripts") -from typing import Optional from furl import furl from requests_html import HTML, HTMLSession +import pandas as pd -class Jczq(object): +from lottery.football import Foootball +from model.football_match import FootballMatch +from model.football_match_spf_odds import FootballMatchSpfOdd +from model.football_match_bf_odds import FootballMatchBfOdd +from model.football_match_bqc_odds import FootballMatchBqcOdd +from model.football_match_zjq_odds import FootballMatchZjqOdd + + +class Jczq(Foootball): ''' 竞彩足球赔率获取 ''' - _base_url = furl("https://trade.500.com/jczq/?g=2") + _base_url = furl("https://trade.500.com/jczq/?g=2&playid=312") + def __init__(self, date_str): + super().__init__() self.session = HTMLSession() self._base_url.args["date"] = date_str - def get_spf_odds(self, d: Optional[str]=None): - self._base_url.args["playid"] = 312 - if d is not None: - self._base_url.args["date"] = d + def get_odds(self): # print(self._base_url.url) r = self.session.get(self._base_url) - bet_trs = r.html.find("tr.bet-tb-tr") - print(len(bet_trs)) - bet_more_trs = r.html.find("tr.bet-more-wrap") - print(len(bet_more_trs)) for tr in zip(bet_trs, bet_more_trs): # 对应竞彩网matchId - match_id = tr[0].attrs["data-id"] + match = self.db.query(FootballMatch).filter_by(issue=tr[0].attrs["data-id"]).first() + if match is not None: + continue + match = FootballMatch() + match.issue = tr[0].attrs["data-id"] match_num = tr[0].attrs["data-matchnum"] - league_name = tr[0].attrs["data-simpleleague"] - home_name = tr[0].attrs["data-homesxname"] - away_name = tr[0].attrs["data-awaysxname"] - match_date = tr[0].attrs["data-matchdate"] + tr[0].attrs["data-matchtime"] - buyendtime = tr[0].attrs["data-buyendtime"] - rangqiu = tr[0].attrs["data-rangqiu"] + match.league_name = tr[0].attrs["data-simpleleague"] + match.home_name = tr[0].attrs["data-homesxname"] + match.away_name = tr[0].attrs["data-awaysxname"] + match.match_date = tr[0].attrs["data-matchdate"] + " " + tr[0].attrs["data-matchtime"] + match.buy_end_time = tr[0].attrs["data-buyendtime"] + match.rq_count = tr[0].attrs["data-rangqiu"] + match.score = tr[0].find("i.team-bf", first=True).text + self.db.add(match) + self.db.commit() + match_id = match.id + match_issue = match.issue # 胜平负 nspf = tr[0].find("td.td-betbtn div.itm-rangB1", first=True) betbtn_ok = nspf.find("p[class$='betbtn-ok']", first=True) + # 比分 if betbtn_ok is not None: result = betbtn_ok.attrs["data-value"] nspf_odds = {i.attrs["data-value"]: i.attrs["data-sp"] for i in nspf.find("p.betbtn")} + # 让球胜平负 spf = tr[0].find("td.td-betbtn div.itm-rangB2", first=True) rq_result = spf.find("p[class$='betbtn-ok']", first=True).attrs["data-value"] spf_odds = {i.attrs["data-value"]: i.attrs["data-sp"] for i in spf.find("p.betbtn")} + spf_model = FootballMatchSpfOdd(match_id=match_id, issue=match_issue, rq_count=match.rq_count, rq_result=rq_result) + spf_model.win = nspf_odds["3"] + spf_model.draw = nspf_odds["1"] + spf_model.lost = nspf_odds["0"] + spf_model.rq_win = spf_odds["3"] + spf_model.rq_draw = spf_odds["1"] + spf_model.rq_lost = spf_odds["0"] + self.db.add(spf_model) # 半全场 bqc = tr[1].find("p[data-type='bqc']") - bqc_odds = {i.attrs["data-value"]: i.attrs["data-sp"] for i in bqc} + bqc_odds = {"_" + i.attrs["data-value"].replace("-", "_"): i.attrs["data-sp"] for i in bqc} bqc_result = tr[1].find("p[class$='sbetbtn-ok'][data-type='bqc']", first=True).attrs["data-value"] + bqc_model = FootballMatchBqcOdd(match_id=match_id, issue=match_issue, result=bqc_result, **bqc_odds) + self.db.add(bqc_model) # 比分 bf = tr[1].find("p[data-type='bf']") bf_odds = {i.attrs["data-value"]: i.attrs["data-sp"] for i in bf} + bf_odds = {("_" + k.replace(":", "_")).replace("_胜其它", "win_others").replace("_平其它", "draw_others").replace("_负其它", "lost_others"): bf_odds[k] for k in bf_odds.keys()} bf_result = tr[1].find("p[class$='sbetbtn-ok'][data-type='bf']", first=True).attrs["data-value"] + bf_model = FootballMatchBfOdd(match_id=match_id, issue=match_issue, result=bf_result, **bf_odds) + self.db.add(bf_model) # 进球数 jqs = tr[1].find("p[data-type='jqs']") - jqs_odds = {i.attrs["data-value"]: i.attrs["data-sp"] for i in jqs} + jqs_odds = {"ball_" + i.attrs["data-value"].replace("7", "7_plus"): i.attrs["data-sp"] for i in jqs} jqs_result = tr[1].find("p[class$='sbetbtn-ok'][data-type='jqs']", first=True).attrs["data-value"] - print(f"{home_name}-{away_name} 赔率:{nspf_odds}, 结果:{result}, 比分:{bf_result},比分赔率:{bf_odds}") -jczq = Jczq("2023-04-15") -jczq.get_spf_odds() + zjq_model = FootballMatchZjqOdd(match_id=match_id, issue=match_issue, result=jqs_result, **jqs_odds) + self.db.add(zjq_model) + self.db.commit() + +if __name__ == "__main__": + # dates = pd.date_range(start='2023-04-15', end='2023-05-13') + # print(dates) + jczq = Jczq("2023-04-15") + jczq.get_odds()