2. What does the library do?
1. Provides you live score of the match
2. Provides you match details(teams,ground,toss,squads etc.)
3. Provides you scorecard of a match
4. Provides you commentary of the match
3. Why did I develop pycricbuzz library
I was inspired by posts on quora which were related to automating stuffs.
Quora link - https://www.quora.com/As-a-programmer-what-tasks-have-you-
automated-to-make-your-everyday-life-easier-How-can-one-expect-to-
improve-life-through-automated-programming
I wrote a script to send me desktop notifications whenever a four, six or wicket
fell.
All the functions contained in pycricbuzz library were a part of that script.
Later, I separated them to build this library.
I open sourced it on git. Didn’t think at that time that it would benefit a lot of
people.
4. Purpose of making this video
To share with everyone how the code works
In case you understand the code, you can add a lot of other features to the
code and improve it.
You can also build many useful tools with the help of resources I am going
to share here.
5. Skills Required
Python
Json
Python requests module
Understanding of python dictionaries and lists
That’s all you need for understanding this code.
6. Fetching cricket scores from cricbuzz
Cricbuzz publicly exposes the cricket scores in json form(They may stop
this someday)
http://mapps.cricbuzz.com/cbzios/match/livematches - This gives us all the
matches that are in progress or recently finished or are upcoming.
It exposes the data in json format. All you need is a requests.get() call to
the url and encode the result in json format.
Let’s open the url and see what all data one can get from it
You get a list of the matches and a brief summary of the match
r = requests.get(url).json()
7. Fetching details of match
Details here are teams, ground, squads, mom, officials, toss etc.
http://mapps.cricbuzz.com/cbzios/match/livematches – This does provides
with enough match details but you have one more way.
http://mapps.cricbuzz.com/cbzios/match/22484– This provides us with
more details than the above url.
Only catch is that it provides squads and teams in form of id’s that have a
mapping. You would need to store this mapping.
At the bottom, you can also see all the api that cricbuzz exposes for a
match.
8. Fetching live score of match
http://mapps.cricbuzz.com/cbzios/match/livematches – You can get the
live score for each match from this endpoint.
http://mapps.cricbuzz.com/cbzios/match/22484/leanback.json – This also
serves the same purpose and provides us with some extra features like
last_wicket, patenership, prev_overs events etc.
Note that in the above endpoint, “22484” is the match id that you can get
from /livematches endpoint.
For my code, I have used the first endpoint.
9. Fetching commentary of a match
http://mapps.cricbuzz.com/cbzios/match/22484/commentary – This
endpoint provides us with commentary for a match
It includes last 3-4 overs commentary
It also includes the match details. You can also use this endpoint to fetch
match details
10. Fetching scorecard of a match
http://mapps.cricbuzz.com/cbzios/match/22484/scorecard – This provides
us with scorecard of a match
All the batsman and bowlers here are represented in form of id’s. So, you
need to store the mapping.
http://mapps.cricbuzz.com/cbzios/match/22484/ - This contains the
mapping id to player mapping
12. Let’s now look at the pycricbuzz code
crawl_url(url)
players_mapping(mid)
matchinfo(mid)
matches()
find_match(id)
livescore(mid)
commentary(mid)
scorecard(mid)
13. How to use the pycricbuzz library
https://shivammitra.com/python/cricket-library-for-python/ - I have
explained here as how to use the library
In case you are facing some problems while using the library, you can
comment it on blog or this video
14. What tools do you have made to
automate stuffs
One of the user of pycricbuzz library told me that he was using it for
getting notifications when a six is hit in a ipl match. Then, he could order
from swiggy and get around Rs. 75 discount
Another user used the library to develop a fantasy website for his college
event
You can also share how you are using the library so that I come to know
about the usecases
You can also share awesome scripts you have written to automate day to
day stuffs