Paul Sutton

weather

Ansi Weather 2

Donate using Liberapay

Further to my previous post on ansi weather

I wrote this, which asks for your location, and displays the weather.

echo "where do you live ?"
read location
ansiweather -l $location

In my previous post I was trying to use sed to clean up the output, this isn't needed as the -a option removes the colour coding from the output

ansiweather -a false -l Plymouth, UK >> weatherinfo.txt

Produces

Weather in Plymouth => -10 °C – Wind => 1.72 m/s NNW – Humidity => 62 % – Pressure => 1028 hPa

Which is far better.

so our new shell script is

1 #send weather info to Mastodon
  2 # current date
  3 date > weatherinfo.txt
  4 # current weather
  5 # use -a false to remove colour from output, set location, output to a file
  6 ansiweather -a false -l Plymouth, UK >> weatherinfo.txt
  7 # output to console too
  8 ansiweather -a false -l Plymouth, UK
  9 #send to Mastodon
 10 toot post < weatherinfo.txt
 11 # done
 12 echo done

So the final output to Mastodon is

Final Output

There are more options in the READ.me file

Thank you to Noisytoot for helping with this.

If you now combine the 2nd script with the one I have at the top of this page you should be able to input your location, then get the local weather.

REFERENCES

TAGS

#YearOfTheFediverse,#ansiweather,#weather,#mastodon,#bash,#console,#terminal #information

Creative Commons Licence
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License


MastodonPeertubeQoto sign up

Donate using Liberapay

Ansi Weather

Donate using Liberapay

Getting weather information is really useful. What happens if you're at the command line in Linux? I found a really little application that can help

ansiweather

apt install ansiweather

ansiweather -l Plymouth, UK

Ansi Weather Output

So what else can we do with this

  1. Send the output to Mastodon with toot post

This is a two step process

  1. ansiweather -l Plymouth, UK > weather.txt
  2. toot post < weather.txt

Will send the weather info to Mastodon.

However this does not include any date info

We can fix this with

  1. date > weatherinfo.txt
  2. ansiweather -l Plymouth, UK >> weatherinfo.txt

then send the whole lot to Mastodon with

  1. toot post < weatherinfo.txt

So, if we put this in to a final shell script we need:-

#send weather info to Mastodon
# current date
date > weatherinfo.txt
# current weather
ansiweather -l Plymouth, UK >> weatherinfo.txt
#send to Mastodon
toot post < weatherinfo.txt
# done
echo done

Again released under GPLv3

I tried to get festival to speak the weather, it is not perfect but this sort of works, you will need to direct to weather.txt first.

festival —tts < weather.txt

Looking in to this further, the issue is the brackets etc, so this stackoverflow post

strips out the colour formatting

sed 's/\x1b[[^\x1b]*m//g' weatherinfo.txt

Therefore

sed 's/\x1b[[^\x1b]*m//g' weatherinfo.txt > weatherinfo2.txt

Sends the newly formatted text to weatherinfo2.txt

So running back through festival

festival —tts < weather.txt

Is perhaps a little better, but not perfect

So going back to what we wrote earlier to send to Mastodon, the new script

  1 #send weather info to Mastodon
  2 # current date
  3 date > weatherinfo.txt
  4 # current weather
  5 ansiweather -l Plymouth, UK >> weatherinfo.txt
  6 # clean up output with sed
  7 sed 's/\x1b\[[^\x1b]*m//g' weatherinfo.txt > weatherinfo2.txt
  8 #send to Mastodon
  9 toot post < weatherinfo2.txt
 10 # done
 11 echo done

Produces much nicer output. The top bottom part of this illustrates what was sent before we stripped out the colour formatting

However it still isn't perfect, as it removes part some of the wording, but it is hopefully getting there.

Weather Output (new)

REFERENCES

TAGS

#YearOfTheFediverse,#Weather,#Scripting,#Bash,#Linux, #Mastodon,#ProblemSolving,#AnsiWeather,#programming, #Stackoverflow,#sed,#cat,#grep,GPL3,#FSF

Creative Commons Licence
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License


MastodonPeertubeQoto sign up

Donate using Liberapay