Skip to content

Instantly share code, notes, and snippets.

@mskian
Forked from arulrajnet/livecricketscore.sh
Last active April 7, 2018 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mskian/1e660a1a205a3b69e698cb0b0256b083 to your computer and use it in GitHub Desktop.
Save mskian/1e660a1a205a3b69e698cb0b0256b083 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
# -----------------------------------------------------------------------------
# Info:
# author: Arulraj <https://arulraj.net/>
# Modified by Santhosh veer <https://santhoshveer.com>
# file: score.sh
# Orginal Gist: https://gist.github.com/arulrajnet/fb71169c35180f9d9abd
# Modified Gist: https://gist.github.com/mskian/1e660a1a205a3b69e698cb0b0256b083
# created: 24.03.2015
# revision: 07.04.2018
# version: 0.5
# -----------------------------------------------------------------------------
# Requirements:
# curl, grep, libxml2-utils
# Description:
# Shell script to get a Live cricket score from www.espncricinfo.com
#
# -----------------------------------------------------------------------------
function get_html() {
local html
html=$(curl -k -L -s "$1")
echo "$html"
}
function get_score() {
while true;
do
get_html "$1" | grep -oP '(?<=<title>).*?(?=</title>)'
#sleep 1m;
sleep 20;
done;
}
function list_live_matches() {
local live_rss=http://static.cricinfo.com/rss/livescores.xml
local rss_content
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 -e "\\033[1;32m Live Cricket Matches \\033[0m"
echo -e "----------------------"
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 -ne "\\033[1;36m Enter the match number : \\033[0m"
read -r 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 "$*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment