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()