Working with the pycricbuzz library in Python
Pycricbuzz is a python library that can be used to get live scores, commentary and full scorecard for recent and live matches.
In case you want to know how the library was developed, you can watch the video: https://youtu.be/OQqYbC1BKxw
Installation: Run the following pip command in the terminal.
pip install pycricbuzz
First of all, we need to create an object of Cricbuzz() for further operations.
Python3
from pycricbuzz import Cricbuzz
c = Cricbuzz()
|
Fetch all the matches provided by Cricbuzz
We use the matches() method to fetch all the live, upcoming and recently finished matches. Each match has an id associated with it.
Python3
from pycricbuzz import Cricbuzz
c = Cricbuzz()
print (c.matches())
|
Output:
The output by default is quite difficult to read. We can use JSON to make the output matches more human-readable.
Python3
from pycricbuzz import Cricbuzz
import json
c = Cricbuzz()
print (json.dumps(c.matches(), indent = 4 ))
|
Output:
Get a particular match’s information
We can use the matchinfo() method to get the information of a particular match. We have to pass the match id in this method.
Python3
from pycricbuzz import Cricbuzz
import json
c = Cricbuzz()
print (json.dumps(c.matchinfo( '30560' ), indent = 4 ))
|
Output:
Fetching the live score of a match
We can fetch the score of a live match by using the livescore() method. Use it only for live matches.
Python3
from pycricbuzz import Cricbuzz
import json
c = Cricbuzz()
print (json.dumps(c.livescore( '30505' ), indent = 4 ))
|
Output:
Fetching the scorecard of a match
We can get the scorecard of a match by using the scorecard() method. Pass the match id of the target match in this method.
Python3
from pycricbuzz import Cricbuzz
import json
c = Cricbuzz()
print (json.dumps(c.scorecard( '30505' ), indent = 4 ))
|
Output:
Fetching the commentary of a match
We can get the commentary of a particular match by using the commentary() method. Pass the match id in this method.
Python3
from pycricbuzz import Cricbuzz
import json
c = Cricbuzz()
print (json.dumps(c.commentary( '30505' ), indent = 4 ))
|
Output:
Last Updated :
01 Nov, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...