Thursday, March 23, 2017

Implementing a Simple Weather ScreenSaver in Linux

Starting with that first real-life tornado experience as a seven year old, I have been intrigued with the weather.  Going back to my college days I would watch the Weather Channel for hours-on-end when not doing school work.  After my freshman year (1985 or 86 or 87; don't remember completely), I passed my ham radio Technician test and was able to participate as a weather spotter.

Wanting to watch the weather on my computer while at work, many years ago I wrote a little program that would rotate the Windows background image through several current weather maps downloaded from NOAA and NWS websites.  Honestly, it worked OK, but not stellar.

Living Las Vegas gave me very little drive to be informed with the weather; it was simply depressing.  Hot... Hot...  OMG Hot... WTF Hot... oh... one nice day.  meh...  FUUU HOT!  I did NOT like the weather there.

Now, living back in the mid-west, I have been gaining interest in watching the weather again.  Since watching any cable weather outlet while working is quite distracting, a weather screen saver is the next best thing.  In this post I will detail how to setup a desktop Linux distribution (Debian "Jessie" to be exact) to download maps and radar images from the NWS and have the screen saver cycle through the images.  Personally, this runs on my spare Linux box next to my work computer.

First, we need a directory to download the weather images into.  I created a wx directory under Pictures. You can put this directory just about anywhere.  In the wx directory I used the nano editor to create a file called getwx.  (Really, any editor can be used.)  Here is what I put in the file:

#Get images for my weather Gallery.
curl > /home/ken/Pictures/wx/EasternUSInfrared.jpg 
curl > /home/ken/Pictures/wx/DavenportRadar.png 
curl > /home/ken/Pictures/wx/CentralILRadar.png 
curl > /home/ken/Pictures/wx/DesMoinesRadar.png 
curl > /home/ken/Pictures/wx/USRadar.png 
curl > /home/ken/Pictures/wx/Forecast.gif 
curl > /home/ken/Pictures/wx/ForecastHighTemps.png 
curl > /home/ken/Pictures/wx/PrecipProbability.png 
curl > /home/ken/Pictures/wx/12hourFronsPrecip.gif 
curl > /home/ken/Pictures/wx/TStorm0000z.gif 
curl > /home/ken/Pictures/wx/TStorm0400z.gif 
curl > /home/ken/Pictures/wx/TStorm1200z.gif 
curl > /home/ken/Pictures/wx/TStorm1600z.gif 
curl > /home/ken/Pictures/wx/TStorm2000z.gif 

[Be certain to use the proper file paths.  The above example is what I entered.  Unless your username is ken, you will likely want to use another path.]

Run chmod a+x getwx from a terminal window to make the file en executable batch file.

Now, add a cron rule to run the script every 15 minutes.  crontab -e allows you to edit your own personal cron schedule file.  Add the following line to the file [using the path where you saved getwx.]:

0,15,30,45 * * * * /home/ken/Pictures/wx/getwx >/home/ken/Pictures/wx/lastWX 2&>1

Before we go on, you should run getwx from a shell prompt just to be certain it works by itself and properly downloads the files and places them where you want them.

The last step is to configure the screen saver.  I selected the GLSlideshow because I know it works and is pretty simple.  After selecting the desired screen saver, go to the advanced tab of the Screensaver Preferences page, select Chose Random Image and then enter the directory where the images are downloaded.  In my case, /home/ken/Pictures/wx/

Once that is working, you can change the files you download by changing the getwx script file.  For that matter, you don't need to download weather images; they can be funny cat pictures or internet comics or just about any graphic content.

Enjoy & have fun with your new screen saver thing. :-)

No comments:

Post a Comment