-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest2.py
30 lines (24 loc) · 1.56 KB
/
test2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import requests
from tabulate import tabulate
def fetch_cricket_scores():
url = "https://cricbuzz-cricket.p.rapidapi.com/matches/v1/recent"
headers = {
"X-RapidAPI-Host": "cricbuzz-cricket.p.rapidapi.com",
"X-RapidAPI-Key": "Replace with your RapidAPI key" # Replace with your RapidAPI key
}
response = requests.get(url, headers=headers)
data = response.json()
matches = data['typeMatches'][0]['seriesMatches'][0]['seriesAdWrapper']['matches']
for match in matches:
table = []
table.append(["Match Description", f"{match['matchInfo']['matchDesc']} , {match['matchInfo']['team1']['teamName']} vs {match['matchInfo']['team2']['teamName']}"])
table.append(["Match Details", ""])
table.append(["Series Name", match['matchInfo']['seriesName']])
table.append(["Match Format", match['matchInfo']['matchFormat']])
table.append(["Result", match['matchInfo']['status']])
table.append([f"{match['matchInfo']['team1']['teamName']}", f"{match['matchScore']['team1Score']['inngs1']['runs']}/{match['matchScore']['team1Score']['inngs1']['wickets']} in {match['matchScore']['team1Score']['inngs1']['overs']} overs"])
table.append([f"{match['matchInfo']['team2']['teamName']}", f"{match['matchScore']['team2Score']['inngs1']['runs']}/{match['matchScore']['team2Score']['inngs1']['wickets']} in {match['matchScore']['team2Score']['inngs1']['overs']} overs"])
headers = ["Key", "Value"]
print(tabulate(table, headers=headers, tablefmt="grid"))
print("\n")
fetch_cricket_scores()