Pycricbuzz 库 - 用于 Python 的板球 API2024 年 8 月 29 日 | 5 分钟阅读 众所周知,Python 拥有庞大的库,板球也并未被忽视。在本教程中,我们将学习用于获取实时比分、评论和近期及直播比赛完整记分卡的 Python 库。 要使用 Pycricbuzz,我们需要使用以下命令安装 Pycricbuzz。 按 Enter 键;它将在系统中安装 pycricbuzz 库。 Pycribuzz 入门Pycricbuzz 库是一个有趣的库,因为它受到板球迷的喜爱。首先,创建一个新的 Python 文件并导入 pycricbuzz。 现在创建 Cricbuzz 对象。 我们可以使用此对象访问 pycricbuzz 提供的所有函数。让我们通过以下示例来理解。 如何获取所有比赛示例 - 输出 [
{
"id": "21653",
"mchstate": "toss",
"mnum": "5th ODI",
"official": {
"referee": {
"country": "Ind",
"id": "3894",
"name": "Javagal Srinath"
},
"umpire1": {
"country": "Afg",
"id": "11150",
"name": "Bismillah Jan Shinwari"
},
"umpire2": {
"country": "Ind",
"id": "7498",
"name": "S Ravi"
},
"umpire3": {
"country": "Afg",
"id": "11152",
"name": "Ahmed Shah Pakteen"
}
},
"srs": "Afghanistan v Ireland in India 2019",
"start_time": "2019-03-10 13:00:00",
"status": "IRE opt to bowl",
"team1": {
"name": "Afghanistan",
"squad": [
"Mohammad Shahzad",
"Javed Ahmadi",
"Rahmat",
"Asghar Afghan",
"Najibullah",
"Shenwari",
"Nabi",
"Rashid Khan",
"Mujeeb",
"Zahir Khan",
"Shapoor"
],
"squad_bench": [
"Hazratullah Zazai",
"Noor Ali",
"Ikram Ali Khil",
"Naib",
"Aftab Alam",
"Dawlat Zadran",
"Shahidi",
"Shirzad",
"Fareed Malik",
"Karim Janat"
]
},
"team2": {
"name": "Ireland",
"squad": [
"Porterfield",
"Stirling",
"Andy Balbirnie",
"Simi Singh",
"Kevin O Brien",
"Dockrell",
"Stuart Poynter",
"Andy McBrine",
"James Cameron",
"Murtagh",
"Rankin"
],
"squad_bench": [
"Chase",
"James McCollum",
"McCarthy",
"Lorcan Tucker",
"S Thompson"
]
},
"toss": "Ireland elect to bowl",
"type": "ODI",
"venue_location": "Dehradun, Uttarakhand, India",
"venue_name": "Rajiv Gandhi International Cricket Stadium"
}
]
解释 - 上面的代码将返回所有比赛的列表以及相关详细信息。每场比赛都有一个 id 属性,用于获取该比赛的评论和记分卡。我们还可以使用以下方法获取比赛详情。 如何获取实时比分我们创建了 live_score() 函数,它接收比赛 id。让我们通过以下代码来理解。 示例 - 输出 {
"batting": {
"batsman": [
{
"balls": "43",
"fours": "0",
"name": "Asghar Afghan",
"runs": "8",
"six": "0"
},
{
"balls": "32",
"fours": "1",
"name": "Nabi",
"runs": "19",
"six": "0"
}
],
"score": [
{
"declare": null,
"inning_num": "1",
"overs": "25.2",
"runs": "77",
"wickets": "4"
}
],
"team": "Afghanistan"
},
"bowling": {
"bowler": [
{
"maidens": "0",
"name": "James Cameron",
"overs": "4.2",
"runs": "15",
"wickets": "0"
}
],
"score": [],
"team": "Ireland"
}
}
解释 - 当我们运行上面的代码时,它会返回比赛以及击球和投球队伍的详细信息。击球手和投球手是指当前正在击球的两名击球手和当前正在投球的两名投球手。 如何获取比赛评论在下面的方法中,我们创建了一个接收比赛 id 的函数。使用 commentary() 方法,我们可以获取评论的名称。让我们通过以下示例来理解。 示例 - 输出 {
"commentary": [
{
"comm": "Simi Singh to Nabi, no run",
"over": "26.2"
},
{
"comm": "Simi Singh to Nabi, no run, tossed up outside off, Nabi gets an inside edge on the clip to short fine",
"over": "26.1"
},
{
"comm": "Asghar Afghan is still struggling from the shoulder injury he sustained in the last match. Winced in pain after that last six, but going on for his team",
"over": null
},
{
"comm": "James Cameron to Asghar Afghan, no run, tossed up on off, Afghan leans well forward and blocks",
"over": "25.6"
},
{
"comm": "James Cameron to Asghar Afghan, no run, flighted on the leg-stump line, clipped straight to the fielder at backward leg, wanted a single and is sent abck",
"over": "25.5"
},
{
"comm": "James Cameron to Asghar Afghan, <b>SIX</b>, that has been <b>thumped</b>, juicy full-toss from Cameron-Dow, Afghan moves across and slugs it high and over backward square leg for a maximum",
"over": "25.4"
},
{
"comm": "James Cameron to Asghar Afghan, <b>FOUR</b>, that's a poor ball from Cameron-Dow, dropped short and wide of off, Afghan made room and slapped it wide of cover - beats the fielder getting across from the deep",
"over": "25.3"
},
{
"comm": "James Cameron to Asghar Afghan, no run, dropped short and wide of off, cracked straight to Dockrell at cover",
"over": "25.2"
},
{
"comm": "James Cameron to Asghar Afghan, no run, turn for Cameron-Dow, but once again the length is short, allows Afghan to push it to the off-side",
"over": "25.1"
},
{
"comm": "Simi Singh to Nabi, no run, full and at the stumps, whipped straight to the fielder at mid-wicket",
"over": "24.6"
}
]
}
解释 - "评论" 是一个包含所有评论文本的列表。 如何获取比赛的记分卡让我们理解下面的例子。 示例 - 输出 {
"scorecard": [
{
"batcard": [
{
"balls": "4",
"dismissal": "c James Cameron b Murtagh",
"fours": "0",
"name": "Mohammad Shahzad",
"runs": "6",
"six": "1"
},
{
"balls": "30",
"dismissal": " b Andy McBrine",
"fours": "2",
"name": "Javed Ahmadi",
"runs": "24",
"six": "1"
},
{
"balls": "42",
"dismissal": "c Stirling b Dockrell",
"fours": "0",
"name": "Rahmat",
"runs": "17",
"six": "1"
},
{
"balls": "47",
"dismissal": "batting",
"fours": "1",
"name": "Asghar Afghan",
"runs": "18",
"six": "1"
},
{
"balls": "1",
"dismissal": "c Andy McBrine b Dockrell",
"fours": "0",
"name": "Shenwari",
"runs": "0",
"six": "0"
},
{
"balls": "38",
"dismissal": "batting",
"fours": "1",
"name": "Nabi",
"runs": "20",
"six": "0"
}
],
"batteam": "Afghanistan",
"bowlcard": [
{
"maidens": "1",
"name": "Murtagh",
"nballs": "0",
"overs": "5",
"runs": "18",
"wickets": "1",
"wides": "0"
},
{
"maidens": "0",
"name": "Rankin",
"nballs": "0",
"overs": "3",
"runs": "13",
"wickets": "0",
"wides": "1"
},
{
"maidens": "1",
"name": "Andy McBrine",
"nballs": "0",
"overs": "5",
"runs": "7",
"wickets": "1",
"wides": "1"
},
{
"maidens": "0",
"name": "Dockrell",
"nballs": "0",
"overs": "6",
"runs": "18",
"wickets": "2",
"wides": "0"
},
{
"maidens": "0",
"name": "James Cameron",
"nballs": "0",
"overs": "5",
"runs": "25",
"wickets": "0",
"wides": "1"
},
{
"maidens": "0",
"name": "Simi Singh",
"nballs": "0",
"overs": "3",
"runs": "7",
"wickets": "0",
"wides": "0"
}
],
"bowlteam": "Ireland",
"extras": {
"byes": "0",
"lbyes": "0",
"nballs": "0",
"penalty": "0",
"total": "3",
"wides": "3"
},
"fall_wickets": [
{
"name": "Mohammad Shahzad",
"overs": "0.4",
"score": "6",
"wkt_num": "1"
},
{
"name": "Javed Ahmadi",
"overs": "11.3",
"score": "39",
"wkt_num": "2"
},
{
"name": "Rahmat",
"overs": "14.3",
"score": "50",
"wkt_num": "3"
},
{
"name": "Shenwari",
"overs": "14.4",
"score": "50",
"wkt_num": "4"
}
],
"inng_num": "1",
"overs": "27",
"runs": "88",
"wickets": "4"
}
]
}
|
我们请求您订阅我们的新闻通讯以获取最新更新。