Skip to content
Related Articles

Related Articles

Improve Article

Working with the pycricbuzz library in Python

  • Last Updated : 01 Nov, 2020

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






# importing the modules
from pycricbuzz import Cricbuzz
  
# creating a Cricbuzz object
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




# importing the modules
from pycricbuzz import Cricbuzz
  
# creating a Cricbuzz object
c = Cricbuzz()
  
# displaying all the matches
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




# importing the modules
from pycricbuzz import Cricbuzz
import json
  
# creating a Cricbuzz object
c = Cricbuzz()
  
# displaying all the matches
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




# importing the modules
from pycricbuzz import Cricbuzz
import json
  
# creating a Cricbuzz object
c = Cricbuzz()
  
# displaying the match information
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




# importing the modules
from pycricbuzz import Cricbuzz
import json
  
# creating a Cricbuzz object
c = Cricbuzz()
  
# displaying the match score
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






# importing the modules
from pycricbuzz import Cricbuzz
import json
  
# creating a Cricbuzz object
c = Cricbuzz()
  
# displaying the match score
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




# importing the modules
from pycricbuzz import Cricbuzz
import json
  
# creating a Cricbuzz object
c = Cricbuzz()
  
# displaying the match commentary
print(json.dumps(c.commentary('30505'), indent = 4))

Output:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :