Skip to content

Instantly share code, notes, and snippets.

@arulrajnet
Last active January 29, 2020 04:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save arulrajnet/fb71169c35180f9d9abd to your computer and use it in GitHub Desktop.
Save arulrajnet/fb71169c35180f9d9abd to your computer and use it in GitHub Desktop.
Shell script to get a Live cricket score from www.espncricinfo.com. Just run this shellscript then select your match. when ever you want to know score open that terminal and see. Just simple as Dhoni's helicopter shot :D
#/bin/bash
# Shell script to get a Live cricket score from www.espncricinfo.com
# To help Cricket fan DevOPS see the score on his Terminal.
# Thanks to ESPN SPORTS MEDIA LTD for their RSS feed.
#
# Author : Arul <mailto:me@arulraj.net>
function get_html() {
local html=$(curl -k -L -s $1)
echo "$html"
}
function get_score() {
while true;
do
get_html $1 | grep -oP '(?<=<title>).*?(?=</title>)'
sleep 1m;
done;
}
function list_live_matches() {
local live_rss=http://static.cricinfo.com/rss/livescores.xml
local rss_content=$(get_html $live_rss)
local rss_file_name="cricinfo_livescores.xml"
echo "$rss_content" > $rss_file_name
no_of_matches=$(xmllint --xpath 'count(/rss/channel/item)' $rss_file_name)
echo "Live Cricket Matches"
echo "--------------------"
for ((i = 1; i <= no_of_matches; i++)); do
title=$(xmllint --xpath '/rss/channel/item['$i']/title/text()' $rss_file_name)
echo "$i: $title"
done
echo -n "Enter the match number : "
read number
if is_integer $number; then
selected_title=$(xmllint --xpath '/rss/channel/item['$number']/title/text()' $rss_file_name 2>/dev/null)
if [[ -z $selected_title ]]; then
echo "Please give correct match number";
rm -f $rss_file_name;
exit 1
else
echo "Selected Match is : $selected_title"
match_link=$(xmllint --xpath '/rss/channel/item['$number']/link/text()' $rss_file_name)
rm -f $rss_file_name
get_score $match_link
fi
else
echo "Please give number"
rm -f $rss_file_name
exit 1
fi
rm -f $rss_file_name
}
function is_integer() {
printf "%d" $1 > /dev/null 2>&1
return $?
}
function main() {
if [[ -z $1 ]]; then
list_live_matches
else
get_score $1
fi
}
main $*
@arulrajnet
Copy link
Author

arulrajnet commented Mar 21, 2015

How to Install

wget --no-check-certificate https://gist.githubusercontent.com/arulrajnet/fb71169c35180f9d9abd/raw/livecricketscore.sh
chmod +x livecricketscore.sh
cp livecricketscore.sh /usr/bin/livecricketscore
sh /usr/bin/livcricketscore

This script using xmllint. So make sure you have that.

To Install xmllint in ubuntu

apt-get update
apt-get install curl libxml2-utils -y

alt

@Ravindraec14
Copy link

How can i display the score on my desktop top right corner in a box.

@ravindragullapalli
Copy link

Not working in Ubuntu 16.04.

@ravindragullapalli
Copy link

Getting this error - /usr/bin/livecricketscore: 8: /usr/bin/livecricketscore: Syntax error: "(" unexpected

@siddharthsharmahy
Copy link

not working on 16.04, @ravindragullapalli you got any solution ?

@arulrajnet
Copy link
Author

@ravindragullapalli @siddharthsharmahy you have to install libxml2-utils and curl.

apt-get update
apt-get install curl libxml2-utils -y

I tried in plain vanilla ubuntu 16.04 its working.
image

Copy link

ghost commented Dec 20, 2017

amazing work @arulrajnet cheers.

@mskian
Copy link

mskian commented Jan 14, 2018

While running on Termux Android Emulator I got this two below errors

for testing, I saved this file as termux.sh

Error 1

while running this command line as sh termux.sh or sh ./termux.sh

selection_001

Error 2

it's work well while running bash termux.sh

but I got this error

selection_002

@mskian
Copy link

mskian commented Jan 14, 2018

if you are using this script on Android device via Termux
you need to install curl & libxml2-utils

  • Curl
pkg install curl

  • libxml2-utils
pkg install libxml2-utils

@mskian
Copy link

mskian commented Jan 25, 2018

its Fixed by adding grep Package

pkg install grep

@vsahil
Copy link

vsahil commented Jan 25, 2019

How can I get a notif whenever the score changes using this script ?

@menporulporiayalan
Copy link

menporulporiayalan commented Jan 13, 2020

Is this still working?

@arulrajnet - When I try to execute I am getting this error -

livecricketscore.sh: 8: Syntax error: "(" unexpected

I tried to install curl by this cmd - Sudo apt-get install curl libxml2-utils -y but I got this below the message.

Reading package lists... Done
Building dependency tree
Reading state information... Done
curl is already the newest version (7.65.3-1ubuntu3).
libxml2-utils is already the newest version (2.9.4+dfsg1-7ubuntu3).
0 upgraded, 0 newly installed, 0 to remove and 35 not upgraded

@j33ty
Copy link

j33ty commented Jan 14, 2020

On mac, changing

get_html $1 | grep -oe '(?<=<title>).*?(?=</title>)'

with

get_html $1 | perl -nle'print if m{(?<=<title>).*?(?=</title>)}' | sed -ne 's/<title>//;s/ - Live -.*//p'

worked!

@menporulporiayalan
Copy link

On mac, changing

get_html $1 | grep -oe '(?<=<title>).*?(?=</title>)'

with

get_html $1 | perl -nle'print if m{(?<=<title>).*?(?=</title>)}' | sed -ne 's/<title>//;s/ - Live -.*//p'

worked!

This method not working in ubuntu 19.10 :(

@arulrajnet
Copy link
Author

Tested with Ubuntu 18.04.3 LTS working as expected.

Tested in docker version of ubuntu:19.10 . There also its working.

@menporulporiayalan Did you ran from bash shell?

@menporulporiayalan
Copy link

@arulrajnet. Yes, I ran from the bash shell.

@menporulporiayalan
Copy link

@arulrajnet. It is working, Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment