55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
import sys
|
|
import os
|
|
sys.path.append(os.curdir)
|
|
|
|
import pandas as pd
|
|
from requests_html import HTMLSession
|
|
from furl import furl
|
|
|
|
from lottery import Lottery
|
|
|
|
# from lottery.football import Foootball
|
|
|
|
class Sporttery(object):
|
|
_base_url = "https://webapi.sporttery.cn/gateway/jc/football/"
|
|
|
|
|
|
def __init__(self, match_begin_date, match_end_date=None, match_page=1, page_no=1, page_size=30, is_fix=0, pc_or_wap=1):
|
|
self.match_begin_date = match_begin_date
|
|
if match_end_date is not None:
|
|
self.match_end_date = match_end_date
|
|
else:
|
|
self.match_end_date = match_begin_date
|
|
self.match_page = match_page
|
|
self.page_no = page_no
|
|
self.page_size = page_size
|
|
self.is_fix = is_fix
|
|
self.pc_or_wap = pc_or_wap
|
|
self.session = HTMLSession()
|
|
|
|
|
|
def get_match_data(self):
|
|
params = dict(matchBeginDate=self.match_begin_date, matchEndDate=self.match_end_date, matchPage=self.match_page,
|
|
pageSize=self.page_size, pageNo=self.page_no, isFix=self.is_fix, pcOrWap=self.pc_or_wap)
|
|
url = furl(f"{self._base_url}/getMatchResultV1.qry").add(params)
|
|
r = self.session.get(url)
|
|
data = r.json()
|
|
return data
|
|
|
|
def get_odds_data(self, match_id):
|
|
params = dict(clientCode=3001, matchId=match_id)
|
|
url = furl(f"{self._base_url}/getFixedBonusV1.qry").add(params)
|
|
r = self.session.get(url)
|
|
data = r.json()
|
|
return data
|
|
|
|
with Lottery() as lottery:
|
|
for date in pd.date_range('2015-02-07', '2023-05-22'):
|
|
for i in range(1, 4):
|
|
sporttery = Sporttery(date.strftime('%Y-%m-%d'), page_no=i)
|
|
data = sporttery.get_match_data()
|
|
match_result_list = data["value"]["matchResult"]
|
|
for match_result in match_result_list:
|
|
lottery.insert_match(match_result["matchId"], **match_result)
|
|
if i+1 > data["value"]["resultCount"]:
|
|
continue |