User:Itu/script/ingv quake2wikitable.sh



# you may improve that script

# https://en.wikipedia.org/wiki/User:Itu/script/ingv_quake2wikitable.sh

echo
echo ' This script produces a wikitable out of the data of cnt.rm.ingv.it/en that you get with the   export list > Text  on the right '
echo 

  # todo: make a request of parameters so the datatable can get downloaded automatically 

arg1=$1  ;  if   [ "$arg1" = ""  ] ;  then  read -p 'Textfile with data?: ' arg1  ; fi

datafile=$arg1 

echo 
echo '<!-- table produced  with https://en.wikipedia.org/wiki/User:Itu/script/ingv_quake2wikitable.sh --> '
echo 
echo '{{clear left}}'
echo '<center>'
echo '{| class="wikitable sortable" style="text-align: center;"'
echo '! rowspan="2" |Date / local time<br /><small>([[Coordinated Universal Time|UTC]])</small> '
echo '! rowspan="2" | [[Moment magnitude scale|Magnitude]]'
echo '! rowspan="2" | Type '
echo '! rowspan="2" | Depth <br />[[Hypocenter]]'
echo '! colspan="3" | [[Epicenter]]'
echo '|-'
echo '! Location'
echo '! [[Latitude]]'
echo '! [[Longitude]]'



while read line 
 do
                                                       ### echo -n $((nn++))"  "
 echo $line | grep -q EventID  &&  continue   # skip headline ( trust on the following order )
  [ "$line" = "" ] &&  continue 

      date=$( echo $line | cut -d'|' -f2 )
  latitude=$( echo $line | cut -d'|' -f3 )
 longitude=$( echo $line | cut -d'|' -f4 )
     depth=$( echo $line | cut -d'|' -f5 )
       mag=$( echo $line | cut -d'|' -f11 )
   magtype=$( echo $line | cut -d'|' -f10 )

  locality=$( echo $line | cut -d'|' -f13 )

if [ $( echo $mag | cut -b1 )  -ge 5  ] ; 
then echo '|- style="background-color:lightblue"'
else echo '|-'
fi

echo '|'$( date -d  $date  "+%Y-%m-%d    %H:%M<small>:%S</small>" )
echo '|'$mag
echo '|'$magtype
echo '|'$depth' km'
echo '|[['$locality']]'
echo '|'$latitude
echo '|'$longitude


 done             < $arg1

echo '|}'
echo '{{clear left}}'
echo '</center>'
echo
echo