For the past few days, I've been disconnected from T.V. and I couldn't keep up with the buzz around. Visiting web portals frequently for updates didn't seem feasible either. The tickers provided by many web portals could've been used, but, unfortunately almost all of them are incompatible with Linux, the beautiful OS.This was the very reason behind me venturing out to code a Breaking News Alert for Linux Machines. And, proudly, I was successful in that. According to the theory that states, "anything good and useful is to be shared", here, I share the source code and instructions to create a custom Breaking News Alert for your Linux Machine/Linux News Ticker

Source Code

In the sample code below, I've used  DNAIndia Latest News Feed
Here is the code for GNOME Desktop Environment

#!/bin/bash
mkdir -p /tmp/dnadata
cd /tmp/dnadata
rm -rf news-latest*
wget http://www.dnaindia.com/services/rss/news-latest.xml
if [[ "$(md5sum news-latest.xml | sed -e 's:news-latest.xml::g')" == "$(md5sum check.xml | sed -e 's:check.xml::g')" ]]
then
echo "same news"
else
cat news-latest.xml | grep 'pubDate' | sed -e 's:<pubDate>::g' | sed -e 's:</pubDate>::g' | head -n 3 | tail -n 1 > 1
cat news-latest.xml | grep 'title' | sed -e 's:<title>::g' | sed -e 's:</title>::g' | head -n 3 | tail -n 1 > 2
cat news-latest.xml | grep -o -P '(?<=<description>).*(?=</description>)' | head -n 3 | tail -n 1 > 3
zenity --display :0 --title="$(cat 2)" --info --text="$(cat 3) \n \n \n \n News as on $(cat 1)"
fi
cat news-latest.xml > check.xml

Here Is Coding For KDE

#!/bin/bash
mkdir -p /tmp/dnadata
cd /tmp/dnadata
rm -rf news-latest*
wget http://www.dnaindia.com/services/rss/news-latest.xml
if [[ "$(md5sum news-latest.xml | sed -e 's:news-latest.xml::g')" == "$(md5sum check.xml | sed -e 's:check.xml::g')" ]]
then
echo "same news"
else
cat news-latest.xml | grep 'pubDate' | sed -e 's:<pubDate>::g' | sed -e 's:</pubDate>::g' | head -n 3 | tail -n 1 > 1
cat news-latest.xml | grep 'title' | sed -e 's:<title>::g' | sed -e 's:</title>::g' | head -n 3 | tail -n 1 > 2
cat news-latest.xml | grep -o -P '(?<=<description>).*(?=</description>)' | head -n 3 | tail -n 1 > 3
kdialog --display :0 --title="$(echo $(cat 2))" --msgbox="$(echo $(cat 3)) n n n n News as on $(echo $(cat 1))"
fi
cat news-latest.xml > check.xml

 

  • Save the Above Script in a File and add it to cron job

To add a cron job use following command
[You need to know VI or VIM for this]

crontab -eu username

replace username with your desired username
and add following entry [ which will check every one minute ]

*/1 * * * * /bin/bash   /path/to/the/file/script &> /dev/null

The above command is set to execute every minute.

Short Description about the Script

This script downloads the specified RSS feed and checks against any old versions of the same. If a change is observed , the script extracts the relevant information from the feed and sends the output to different files. These are then displayed using the ALERT command.
PS. This script needs an active Internet connection for its successful execution. (Duh!!)

You can use any other news feed for your Breaking News Alert Box/Live News Ticker on your Linux Machine. If you're stuck with that or need help/guidance with regard to the code, kindly drop a comment with your original email, so that I could personally respond to you.

Special Thanks To Aravind Jose T. for helping me to pep-up this post !!