#!/bin/bash
# # # Description
# Grap 4 weather stations' data
#
# */15 * * * * /home/michael/common/bin/attictemps
#
# Script=attictemps
# Author=Michael
# Email=use website contact
# Website=http://www.inet-design.com/
# License=GPL
# Script repository=none
# # # # #
#
# # # Be Nice
renice -n 15 -p $$ >/dev/null 2>/dev/null
# # # #

# Include Standard Paths & Functions
IncFile="$(dirname "${BASH_SOURCE[0]}")/includes/stdpaths.sh"
if [ -f "$IncFile" ] ; then
  . "$IncFile"
else
  echo 'No Standard Paths!  Exiting'
  exit 1
fi
IncFile="$(dirname "${BASH_SOURCE[0]}")/includes/stdfunctions.sh"
if [ -f "$IncFile" ] ; then
  . "$IncFile"
fi

# # # #
# Static Setups
# Random user aget
UserAgent=`randomUserAgent`
# # # #

cd "/home/michael/data/trash/attictemps"

StationNames=(
KTNMURFR95
KTNMURFR26
KTNMURFR129
KTNMURFR72
)

DateTime=`date +"%Y%m%d%H%M"`

echo -n "$DateTime" >> attictemps.csv

for StationName in "${StationNames[@]}"; do 
  echo "$StationName.$DateTime"
wget \
--user-agent="$UserAgent" \
--passive-ftp \
--execute robots=off \
--output-document="$StationName.$DateTime" \
--append-output wget-attictemps.log \
"https://www.wunderground.com/dashboard/pws/$StationName"

  temp=`grep '&q;temp&q;:' "$StationName.$DateTime" | sed 's/.*\&q;temp\&q;:\(.*\),\&q;heatIndex\&q.*/\1/'`
  echo -n ",$temp" >> attictemps.csv
  rm "$StationName.$DateTime"  2>/dev/null
done

echo "" >> attictemps.csv
