# bash

## February 5, 2021

Ansi Weather 2

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 ?"
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 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 This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License ## January 30, 2021 Ansi Weather 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 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. REFERENCES TAGS This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License ## January 6, 2021 Site Index 1. Click on a link. 2. Scroll to bottom of page. • Any posts / pages within this blog will be displayed. ## A ## B ## C ## D ## E ## F ## G ## H ## I ## J ## K ## L ## M ## N ## O ## P ## Q ## R ## S ## T ## U ## V ## W ## X ## Y #YearOfTheFediverse ## Z #Zoo ## December 25, 2020 console / terminal xmas tree Nice shell script to make a colour Christmas tree on your terminal / console This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License ## December 9, 2020 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: Example logo file to insert 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 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 : 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

You can find me on Friendica at zleap@social.isurf.ca

Licenced under Attribution 4.0 International (CC BY 4.0)

## March 2, 2020

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 \

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.
\begin{longtable}{llllll}