Cricket score in command line
using python and open cricscore api


Earlier I developed a simple cricket score api known as cricscore-api which gets data from cricinfo website.
It was developed to support a simple Android App back then.
Later it was open sourced for everyone.


Cricscore API has 2 simple APIs.

  1. List all matches
    As shown below, it returns list of matches, along with match id.

    $ curl ""
    # line breaks added to the output for readability.
        {"id":959389,"t2":"Pakistan A","t1":"England Lions"}
  2. Get detail for specific match.
    Take the id of the match of interest and use it as query parameter to same end point.

    $ curl ""
    # line breaks added to the output for readability.
            "de":"2nd T20I: Australia v India at Melbourne, Jan 29, 2016",
            "si":"Australia v India"


  1. Show the score of a particular match in the console.
  2. Output new score detail, whenever it changes.


Self explanatory for python people.
In line comments (starting with #) for everyone else.

import urllib2, json, time

# Score set to empty initially.
score = ''

# Run forever
while True:
    # Fetch the url for the specific match.
    response = urllib2.urlopen('')

    # Get the score details `de` from the response json.
    data = json.load(response)
    new_score = data[0]['de']

    # Whenever score changes, print to console.
    if(new_score != score):
        print new_score
        score = new_score

    # Give a break, hit API after 2 seconds.

Run it

  1. Store the above code in file with required match id.
  2. Run python
  3. Ctrl + C to exit the script.


This code can be further developed, to select the match in the command line itself.
You are free to do so, I may not find time.


Later, I will add output for a live match in Run it section.


Great!! You read till this point, just go ahead and share this post to your followers, collegues and friends. Thanks!

About Author

Sakthi Priyan H
Passionate Programmer

  • I am passionate about building excellent teams, processes and systems.
  • Primarily I use Java, Scala and Python for building various systems and tools.
  • Building API services, Big data processing and Machine Learning systems in Crayon Data.
  • Also, interested in Golang and building web apps using Javascript ecosystem.
  • I wrote my first program in BASIC in 1998, Passionate about computers since then.