Program to fetch live cricket score and give score notification periodically

This program help you to fetch live cricket score and display it on command line. GUI notification will work on Ubuntu.

Dependencies:

* Python 2.x
* BeautifulSoup < to parse HTML>
* Requests <HTTP library for human beings>

Download the dependencies and install by running # python setup.py install, after uncompromising the each dependencies.

Platform: 

Cross platform

Functionality:

Program will give you a list of cricket matches with score and wicket details. When you choose a match, live score of the match would be display along with additional details (wicket, batsman, bowler and over).

You can continue to get the live score on command line and Ubuntu GUI if you enter 'y' when it prompts for notification and there by you will be asked to enter interval period to fetch the live score details.




Do keyboard interrupt (ctrl +c/z/d) to exit from the program.

Program:

from bs4 import BeautifulSoup
import requests
import time
import sys, os
import subprocess as SE

cricinfoRss = 'http://static.cricinfo.com/rss/livescores.xml'

def getURLtext(url):
    retryCount = 5
    r = requests.get(url)
    while r.status_code is not 200:
        if retryCount == 0:
            print 'Check your internet connectivity'
            sys.exit(1)
        retrycount -= 1
        print 'Request failed, trying again..'
        time.sleep(3)
        r = requests.get(url)
    data  = r.text
    soup = BeautifulSoup(data)
    return soup

def findMatches():
    global allMatches
    liveMatches = getURLtext(cricinfoRss)
    allMatches = liveMatches.find_all('description')

    if len(allMatches) > 1:
        askUser()

def askUser():
    global choice
    for index, game in enumerate(allMatches[1:], 1):
        print '%d.'%index , str(game.string)
   
    choice = int(input('Choose preferred match:\n'))

    while True:
        if choice in range(1, index + 1):
            break
        choice = int(input('Invalid Choice. Enter your choice: '))

def guiNotify(message):
    if os.path.isfile('/etc/lsb-release'):
        SE.Popen(['notify-send', message])

def getScore():
    scoreURL = str(allMatches[choice].find_next_sibling().string)
    mainPage = getURLtext(scoreURL)
    score = str(mainPage.title.string).split('|')[0]
    inningsReq = mainPage.find("div", { "class" : "innings-requirement" }).string.strip()
    message = score + inningsReq
    guiNotify(message)
    print message

try:
    findMatches()
    getScore()
    notify = raw_input('Would you like to get notification?\nEnter (y|n)\n>')
    if notify == 'y':
        min = int(input('How many minutes once you would like to get notified?\nEnter min>') )
        while True:
            time.sleep(min * 60)
            getScore()
except KeyboardInterrupt:
    print 'keyboard interrupted, program end'

Post a Comment

9 Comments

  1. That's really useful piece of code for live cricket score admin. I'm glad you are maintaining such useful website.

    ReplyDelete
  2. Bankruptcy is the more regrettable thing that can happen to any mortgage holder. This has heavier effect on your FICO rating since this gives a feeling that you are not able to pay any credit sum that you may owe. live score

    ReplyDelete
  3. Live cricket score and display it on command line. GUI notification will work on Ubuntu.sports scores

    ReplyDelete
  4. Thousands of individuals enjoy cricket around the world whether it be recreational or professional. The game brings physical, sociable and mental advantages to people of all ages. As with most physical exercise, taking part can develop endurance along with bowling, hitting, catching and sprinting abilities. Furthermore, it can benefit children by building their co-ordination skills. ipl schedule 2021

    ReplyDelete
  5. Kochi (earlier known as Cochin) is known by a lot of names such as Queen of Arabian Sea, home to one of the biggest shipyards in India, upcoming metropolitan city of Kerala and more. Now, the people of Kochi have one more reason to celebrate. The Indian Premier League has selected Kochi as one of the two teams to play the IPL in 2011. IPL live score 2021

    ReplyDelete
  6. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me. livescore

    ReplyDelete
  7. I am attracted by the info which you have provided in the above post. It is genuinely good and beneficial info for us. Continue posting, Thank you..Cricket Equipment In Sweden

    ReplyDelete
  8. Can i use this on Online Cricket Streaming website? To fetch live score.

    ReplyDelete
  9. Thank you for sharing an amazing & wonderful blog. This content is very useful, informative and valuable in order to enhance knowledge. Keep sharing this type of content with us & keep updating us with new blogs. Apart from this, if anyone who wants to join the Python with data science training institute in Delhi, can contact 9311002620 or visit our website-
    https://www.htsindia.com/Courses/python/python-with-data-science-training-course

    ReplyDelete