def _tanfuku_common( self, target_date: date, jyo_cd: int, race_no: int, num: int, kake: str ) -> list: """ # 2 3連単,3連複共通部分を関数化 Parameters --------- num: int 2 or 3 kake : str rentan or renfuku Returns ------- odds_matrix : list oddsのリスト(htmlのテーブルと同配列) 要素は少数型 """ assert kake in ["rentan", "renfuku"] assert num in [2, 3] # num = 2ならtypeによらずtype='tf' if num == 2: html_type = "tf" elif kake == "rentan": html_type = "t" elif kake == "renfuku": html_type = "f" else: html_type = "tf" # htmlをload target_url = ( f"https://boatrace.jp/owpc/pc/race/odds{num}{html_type}?" f"rno={race_no}&" f"jcd={jyo_cd:02}&hd={target_date.strftime('%Y%m%d')}" ) lx_content = GetParserContent.url_to_content( url=target_url, content_type="lxml" ) # 3連単と共通-------------------- # oddsテーブルの抜き出し if num == 2 and kake == "renfuku": table_xpath = ( "/html/body/main/div/div/div/div[2]/div[8]/table/tbody" ) else: table_xpath = ( "/html/body/main/div/div/div/div[2]/div[6]/table/tbody" ) # 横優先のoddsリスト odds_el = lx_content.xpath( "/".join([table_xpath, "tr/td[contains(@class, 'oddsPoint')]"]) ) odds_horizontals = list( map(lambda x: self._check_ketsujyo(x.text), odds_el) ) return odds_horizontals
def test_three_renfuku( self, target_date: date, target_jyo: int, race_no: int, ex_three_renfukus: List[Tuple[int, int, int, float]], mocker, ): filename = ( f"odds_3fuku_" f"{target_date.strftime('%Y%m%d')}{target_jyo}{race_no}.html") filepath = FILEPATH / filename lx_content = GetParserContent.file_to_content(filepath, "lxml") mocker.patch.object(GetParserContent, "url_to_content", return_value=lx_content) oif = OddsInfoFactoryImpl() three_renfukus = oif._three_renfuku(target_date, target_jyo, race_no) three_renfukus = asdict(three_renfukus) for ex_three_renfuku in ex_three_renfukus: fst = ex_three_renfuku[0] snd = ex_three_renfuku[1] trd = ex_three_renfuku[2] expected = ex_three_renfuku[3] assert three_renfukus[f"comb_{fst}{snd}{trd}"] == expected
def test_getinfo( self, target_date: date, ex_names: list, ex_codes: list, ex_shinkos: list, ex_ed_races: list, mocker, ): filename = FILEPATH / f"ghp_{target_date.strftime('%Y%m%d')}.html" lx_content = GetParserContent.file_to_content(filename, "lxml") mocker.patch.object(GetParserContent, "url_to_content", return_value=lx_content) rif = RaceInfoFactoryImpl() holdrace_info_itr = rif.getinfo(target_date=target_date) names = list() codes = list() shinkos = list() ed_races = list() for hri in holdrace_info_itr: assert hri.date == target_date names.append(hri.jyo_name) codes.append(hri.jyo_cd) shinkos.append(hri.shinko) ed_races.append(hri.ed_race_no) assert names == ex_names assert codes == ex_codes assert shinkos == ex_shinkos assert ed_races == ex_ed_races
def _raceinfo(self, target_date: date, jyo_cd: int, race_no: int) -> ResultInfo: target_url = (f"http://boatrace.jp/owpc/pc/race/raceresult?" f"rno={race_no}&" f"jcd={jyo_cd:02}&" f"hd={target_date.strftime('%Y%m%d')}") self.logger.debug(f"Get result from {target_url}.") lx_content = GetParserContent.url_to_content(url=target_url, content_type="lxml") common = self._commoninfo(lx_content) players = list(self._playerinfo(lx_content)) self.logger.debug("Completed.") return ResultInfo(target_date, jyo_cd, race_no, common, players)
def _raceinfo(self, target_date: date, jyo_cd: int, race_no: int) -> ChokuzenInfo: target_url = (f"https://boatrace.jp/owpc/pc/race/beforeinfo?" f"rno={race_no}&" f"jcd={jyo_cd:02}&" f"hd={target_date.strftime('%Y%m%d')}") self.logger.debug(f"get html: {target_url}") lx_content = GetParserContent.url_to_content(url=target_url, content_type="lxml") # common common = self._commoninfo(lx_content) players = list(self._playersinfo(lx_content)) return ChokuzenInfo(target_date, jyo_cd, race_no, common, players)
def _raceinfo( self, target_date: date, jyo_cd: int, race_no: int ) -> ProgramInfo: # htmlをload target_url = ( f"https://boatrace.jp/owpc/pc/race/racelist" f"?rno={race_no}" f"&jcd={jyo_cd:02}" f"&hd={target_date.strftime('%Y%m%d')}" ) self.logger.debug(f"get html: {target_url}") lx_content = GetParserContent.url_to_content( url=target_url, content_type="lxml" ) self.logger.debug("get html completed.") common = self._commoninfo(lx_content) players = list(self._playersinfo(lx_content)) return ProgramInfo(target_date, jyo_cd, race_no, common, players)
def test_tansho( self, target_date: date, target_jyo: int, race_no: int, ex_tanshos: List[Tuple[int, float]], mocker, ): filename = ( f"odds_1tan_" f"{target_date.strftime('%Y%m%d')}{target_jyo}{race_no}.html") filepath = FILEPATH / filename lx_content = GetParserContent.file_to_content(filepath, "lxml") mocker.patch.object(GetParserContent, "url_to_content", return_value=lx_content) oif = OddsInfoFactoryImpl() tanshos = oif._tansho(target_date, target_jyo, race_no) tanshos = asdict(tanshos) for ex_tansho in ex_tanshos: fst = ex_tansho[0] expected = ex_tansho[1] assert tanshos[f"comb_{fst}"] == expected
def test_raceinfo( self, target_date: date, target_jyo: int, race_no: int, ex_common: ProgramCommonInfo, ex_p1: ProgramPlayerInfo, ex_p2: ProgramPlayerInfo, mocker, ): filepath = ( FILEPATH / f"pro_{target_date.strftime('%Y%m%d')}{target_jyo}{race_no}.html") lx_content = GetParserContent.file_to_content(filepath, "lxml") mocker.patch.object(GetParserContent, "url_to_content", return_value=lx_content) pif = ProgramInfoFactoryImpl() programinfo = pif._raceinfo(target_date, target_jyo, race_no) assert programinfo.common == ex_common assert programinfo.players[ex_p1.waku - 1] == ex_p1 assert programinfo.players[ex_p2.waku - 1] == ex_p2
def test_raceinfo( self, target_date: date, target_jyo: int, race_no: int, ex_common: WeatherInfo, ex_players: List[ChokuzenPlayerInfo], mocker, ): filename = ( f"choku_{target_date.strftime('%Y%m%d')}{target_jyo}{race_no}.html" ) filepath = FILEPATH / filename lx_content = GetParserContent.file_to_content(filepath, "lxml") mocker.patch.object( GetParserContent, "url_to_content", return_value=lx_content ) chif = ChokuzenInfoFactoryImpl() chokuinfo = chif._raceinfo(target_date, target_jyo, race_no) assert chokuinfo.common == ex_common for ex_p in ex_players: assert chokuinfo.players[ex_p.waku - 1] == ex_p
def test_raceinfo( self, target_date: date, target_jyo: int, race_no: int, ex_common: ResultCommonInfo, ex_players: List[ResultPlayerInfo], mocker, ): filepath = ( FILEPATH / f"res_{target_date.strftime('%Y%m%d')}{target_jyo}{race_no}.html" ) lx_content = GetParserContent.file_to_content(filepath, "lxml") mocker.patch.object( GetParserContent, "url_to_content", return_value=lx_content ) rif = ResultInfoFactoryImpl() resinfo = rif._raceinfo(target_date, target_jyo, race_no) assert resinfo.common == ex_common for ex_p in ex_players: assert resinfo.players[ex_p.waku - 1] == ex_p
def _tansho(self, target_date: date, jyo_cd: int, race_no: int) -> Tansho: # htmlをload target_url = ( f"https://boatrace.jp/owpc/pc/race/oddstf?" f"rno={race_no}&" f"jcd={jyo_cd:02}&" f"hd={target_date.strftime('%Y%m%d')}" ) lx_content = GetParserContent.url_to_content( url=target_url, content_type="lxml" ) target_xpath = ( "/html/body/main/div/div/div/div[2]" "/div[5]/div[1]/div[2]/table/tbody/" "tr/td[contains(@class, 'oddsPoint')]" ) odds_els = lx_content.xpath(target_xpath) odds_list = list(map(lambda x: self._check_ketsujyo(x.text), odds_els)) content_dict = {} for key_name in Tansho.__annotations__.keys(): content_dict[key_name] = odds_list.pop(0) return Tansho(**content_dict)