import sys import os sys.path.append(os.curdir) import pandas as pd from requests_html import HTMLSession from furl import furl from football import Foootball class Sporttery(Foootball): _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): super().__init__() 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, page_no=None): if page_no is None: 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) else: params = dict(matchBeginDate=self.match_begin_date, matchEndDate=self.match_end_date, matchPage=self.match_page, pageSize=self.page_size, pageNo=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 def main(): for date in pd.date_range('2023-05-20', '2023-05-20'): with Sporttery(date.strftime('%Y-%m-%d')) as sporttery: for i in range(1, 4): data = sporttery.get_match_data(page_no=i) match_result_list = data["value"]["matchResult"] for match_result in match_result_list: sporttery.insert_match(match_result["matchId"], **match_result) if i + 1 > data["value"]["resultCount"]: continue if __name__ == "__main__": main()