Paul Sutton

BASH

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

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

Adding CC Images To Photos

This is a re-post from December 2019

If you create lots of media such as photos or graphics. You may want to add information pertaining to the copyright (or ideally copyleft) of the image.

As I am interested in Creative Commons (CC) then it makes sense to be able to add one of the many creative commons license logos to an image.

I asked on Friendica about how to do this (having tried and failed before) and was provided with some help and a really useful shell script to automate the process.

Firstly we need an image to modify and a logo image to add to this:

cc-by logo

Example logo file to insert

cc-by logo

For the sake of this article, I am just using a random photo I took of Paignton Geopark. I have also reduced the image size to 640×480 to make it smaller for the website as per command below.

gm mogrify -resize 640×480 *.JPG

I also had to convert the jpg files to png files with the following

gm convert DSCF0182mod.jpg DSCF0182mod.png

So that this blog would display the images.

The next step is to create a folder structure to contain what we need to undertake the work.

What we need is a new folder

Inside this, we need another folder called out

mkdir out

we need some more files mostly the cc logos, these are available from a simple duckduckgo search.

Note if putting on a website or other media you need to properly include the creative commons license being used on here I have put

''' Licenced under Attribution 4.0 International (CC BY 4.0) '''

Which should then link to the human readable license terms you want to use.

So what we should have is

\insertcc-logo\insertcc.sh

\insertcc-logo\out

\insertcc-logo\out\88×31.png

\insertcc-logo\out\88×31-sa.png

\insertcc-logo\out\cc-zero.png

etc

Put the SOURCE FILE in \insertcc-logo

MODIFY AND RUN the script below

Our script looks like ( save this as insertcc.sh or what you want to call this )

for p in *.JPG; do convert “$p” ./out/88×31.png -gravity southeast -geometry +10+10 -composite “out/$p”; done

What the script does is take each file with the JPG extension (or other extension), add the required logo, and save the modified file in

\insertcc-logo\out

As per :

cc-by logo

You need to make sure that the script points to the correct source files.

You also need to point the script to the correct file you want to insert in to your source image.

for p in *.JPG;

To use a different logo change this section of the script

$p” ./out/88×31.png

This article originally appeared on http://www.zleap.net.

#photo,#embed,#add,#creativecommonslogo,#linux #graphicsmagick,#editing,#manipulation,#bash,#commands, #media,#copyleft,#attribute,#share,#alike,#sharealike, #commons,#freedom,

You can find me on Friendica at [email protected]


cc-by logo

Licenced under Attribution 4.0 International (CC BY 4.0)

Script for $\LaTeX$ Tables

I was asked in irc ( ##chemistry on frenode) about a project to create a table for periodic table data in $\LaTeX$.

This post, is meant to be a rough guide. You are expected to do your own research in to any specific features you need.

As there are now about 120 elements, doing this manually could be rather long winded. So I am trying to develop a small shell script to help with this process.

Firstly Looking at loops in Bash

now how to generate a basic table in $\LaTeX$

\begin{table}[]
\begin{tabular}{llllll}
 &  &  &  &  & 
\end{tabular}
\caption{}
\label{tab:my-table}
\end{table}

This is for a 1 row table, to add multiple rows, you need to add \ at the end of the row as in:-

\begin{table}[]
\begin{tabular}{llllll}
 
 &  &  &  &  &  \\
 &  &  &  &  &  \\
 &  &  &  &  & 
\end{tabular}
\caption{}
\label{tab:my-table}
\end{table}

The following shell script should help us with this.

Please note that the \, should be removed from the very last row.

I have added a script for 10 rows. This can be changed via the shell script.

 1 #!/bin/bash
  2 
  3 echo " " > data.txt
  4 echo "\begin{table}[]" > data.txt
  5 echo "\begin{tabular}{llllll}" >> data.txt
  6 #wc -l data.txt
  7 
  8 for i in {1..10..1}
  9   do 
 10 
 11      #echo "hello"
 12      echo  "&  &  &  &  & \\" >> data.txt
 13  done
 14 #wc -l data.txt
 15  echo  "\end{tabular}" >> data.txt
 16  echo  "\caption{}" >> data.txt
 17  echo  "\label{tab:my-table}" >> data.txt
 18  echo  "\end{table}" >> data.txt

Required table headings were : atom ; r atomic ; density ; Tf ; Tg ;... ?

Table headings are obviously at the top, therefore, once you have run the script and generated the right number of rows amending the first row to

& atom & r atomic & density & Tf & Tg \

Should give the required headings

I have added some word count (wc) to help with diagnostics.

You will need to change the output file extension to .tex for a $\LaTeX$ file. I'll leave it as data.txt as you need to add the other components of a $\LaTeX$ document anyway.

If the table spans more than 1 page then the table should use

\begin{longtable}{llllll}
\end{longtable}

#chemistry, #typesetting, #bash, #LaTeX, #tables, #scripting

You can find me on Friendica at [email protected]