ru us

How to make a script that tells the weather.

 Weather Forecast by Voice of FreeBSD 11.

 I often saw people watching weather forecasts at work, looking for data on some sites, or acquaintances asking me:

 - did you watch the weather.

 This is not for me, I don’t want to look for weather on websites, look at data for a certain period and compare them with other sources.  I always thought that at any moment you can look at a thermometer in the kitchen and dress according to the weather.  Therefore, I wrote a simple Shell script for the Bourne shell script that just clicks on it and tells the weather at the moment.  Yes, there are cases of work or domestic nature when you need to know in advance, for example when there will be frosts.  For these purposes, you can always change the script.

 Under the article, watch a demo video of this script.

 Let's start writing the script.

 First, we need to install and configure a speech synthesizer called Festival.  I already wrote how to do this in the FreeBSD operating system on my website, so now I will not talk about it, but I will go directly to the script.  How to install the Festival speech synthesizer on FreeBSD can be found in my previous article, "Learning to Speak FreeBSD."

 So create a file with any name with the extension sh, I have it pogoda.sh.  We write the following lines into it:





wget -q -O- "$URL" | awk -F\' '/acm_RecentLocationsCarousel\.push/{print $10". градусов сейчас в. " }'| head -1 > /tmp/pogoda

wget -q -O- "$URL" | awk -F\" '/acm_RecentLocationsCarousel\.push/{print $2"." }'| head -1 >> /tmp/pogoda

wget -q -O- "$URL" | awk -F\: '/acm_RecentLocationsCarousel\.push/{print $9"." }'| head -1 >> /tmp/pogoda

festival --language russian --tts /tmp/pogoda


That's the whole script, it will create a pogoda file in the / tmp directory in which it will record weather data in your city.  And the Festival speech synthesizer will already read the contents of the pogoda file.

 The example shows the city of Kiev. This is the top line of the URL.




To select Moscow, we write:




Thus, you can choose any city.

Oh yes, and don't forget to make the script an executable command:


chmod a+x


Everything is ready, watch the video.

Loading Conversation