Compare commits
No commits in common. "master" and "v0.1" have entirely different histories.
16
CHANGELOG
16
CHANGELOG
@ -1,20 +1,4 @@
|
||||
2014-01-03
|
||||
Version 0.1 - First release of the plugin
|
||||
|
||||
2014-01-04
|
||||
Version 0.2 - Fixed two bugs, whereas one important
|
||||
1. In case there more than one wheater alert for the specified
|
||||
region, the script would bug out. Fixed by adding 'head -n1'
|
||||
so that it always only shows the first warning issued.
|
||||
2. In case there were swedish characters (åäö) in the warning
|
||||
message they would output as their HTML-equivalent. Fixed
|
||||
with another sed substitue command.
|
||||
|
||||
2014-01-09
|
||||
Version 0.3 - SMHI has changed österlen to Österlen in the text. Updated this
|
||||
in the hardcoded region/district names.
|
||||
|
||||
2014-01-09
|
||||
Version 0.4 - Fixed an important bug. If the district/region did not exist
|
||||
the script exited with a status 0 (OK). This should be status 3
|
||||
(Unknown). This is now fixed.
|
||||
|
@ -21,14 +21,14 @@
|
||||
################################################################################
|
||||
|
||||
# check_smhi
|
||||
Version="0.4"
|
||||
Version="0.1"
|
||||
Author="Jack-Benny Persson (jack-benny@cyberinfo.se)"
|
||||
|
||||
# Binaries
|
||||
Which="/usr/bin/which"
|
||||
# Binaries entered in the list will be avalible to the script as variables with
|
||||
# the first letter uppercase
|
||||
Binaries=(sed awk egrep printf curl head)
|
||||
Binaries=(sed awk egrep printf curl)
|
||||
|
||||
# Variables
|
||||
District=""
|
||||
@ -59,8 +59,8 @@ AvailDistricts=(
|
||||
"Jämtlands län, Jämtlandsfjällen"
|
||||
"Västerbottens län, södra Lapplandsfjällen"
|
||||
"Norrbottens län, norra Lapplandsfjällen"
|
||||
"Skåne län utom Österlen"
|
||||
"Skåne län, Österlen"
|
||||
"Skåne län utom österlen"
|
||||
"Skåne län, österlen"
|
||||
"Blekinge län"
|
||||
"Hallands län"
|
||||
"Kronobergs län, västra delen"
|
||||
@ -113,7 +113,7 @@ print_help()
|
||||
Options:
|
||||
-D
|
||||
District to check for wheather alerts.
|
||||
NOTE: Districts must be quoted, such as "Skåne län utom Österlen"
|
||||
NOTE: Districts must be quoted, such as "Skåne län utom österlen"
|
||||
-P
|
||||
Print a list with all the avaliable districts.
|
||||
-h
|
||||
@ -145,7 +145,7 @@ if [ $# -eq 0 ]; then
|
||||
exit $State_unknown
|
||||
|
||||
elif [ $# -ge 1 ]; then
|
||||
echo "$1" | $Egrep -q "\-."
|
||||
echo "$1" | egrep -q "\-."
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "$0 requires an option"
|
||||
print_help
|
||||
@ -184,7 +184,7 @@ Index=0
|
||||
Match=0
|
||||
|
||||
while [ $Index -lt $Tot ]; do
|
||||
echo ${AvailDistricts[$Index]} | $Egrep -x "$District" &> /dev/null
|
||||
echo ${AvailDistricts[$Index]} | egrep -x "$District" &> /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
Match=1
|
||||
break
|
||||
@ -195,17 +195,16 @@ done
|
||||
if [ $Match -eq 0 ]; then
|
||||
echo "District $District does not exist"
|
||||
print_help
|
||||
exit $State_unknown
|
||||
fi
|
||||
|
||||
|
||||
### Main ###
|
||||
|
||||
# Fetch the warning page
|
||||
Data=`$Curl -s http://www.smhi.se/vadret/vadret-i-sverige/Varningar/varning_tabell_n1_sv.htm`
|
||||
Data=`curl -s http://www.smhi.se/vadret/vadret-i-sverige/Varningar/varning_tabell_n1_sv.htm`
|
||||
|
||||
# First we must replace all åäö with their HTML equivalent
|
||||
HtmlDist=`echo $District | $Sed '{
|
||||
HtmlDist=`echo $District | sed '{
|
||||
s/å/\å\;/g
|
||||
s/Å/\Å\;/g
|
||||
s/ä/\ä\;/g
|
||||
@ -215,24 +214,17 @@ s/Ö/\Ö\;/g
|
||||
}'`
|
||||
|
||||
# Get the line number for the current district in the HTML-file and add one line to it
|
||||
LineNr=`echo "$Data" | $Sed -n "/$HtmlDist/=" | $Head -n1`
|
||||
LineNr=`echo "$Data" | sed -n "/$HtmlDist/="`
|
||||
((LineNr++))
|
||||
|
||||
# Read the warning message (for example kuling, orkan, åska)
|
||||
WarnMsg=`echo "$Data" | $Sed -n "${LineNr}p" | $Egrep -o "Varning klass [0-3] .*" | \
|
||||
$Sed 's/\(.*\).........../\1/' | \
|
||||
$Awk '{print substr($0, index($0,$4))}' | $Sed '{
|
||||
s/\å\;/å/g
|
||||
s/\Å\;/Å/g
|
||||
s/\ä\;/ä/g
|
||||
s/\Ä\;/Å/g
|
||||
s/\ö\;/ö/g
|
||||
s/\Ö\;/Ö/g
|
||||
}'`
|
||||
WarnMsg=`echo "$Data" | sed -n "${LineNr}p" | egrep -o "Varning klass [0-3] .*" | \
|
||||
sed 's/\(.*\).........../\1/' | \
|
||||
awk '{print substr($0, index($0,$4))}'`
|
||||
|
||||
# Get the current warning class (1, 2 and 3)
|
||||
Class=`echo "$Data" | $Sed -n "${LineNr}p" | $Egrep -o "Varning klass [0-3]" \
|
||||
| $Awk '{ print $3 }'`
|
||||
Class=`echo "$Data" | sed -n "${LineNr}p" | egrep -o "Varning klass [0-3]" \
|
||||
| awk '{ print $3 }'`
|
||||
|
||||
# Chech the current warning class issued for the district
|
||||
if [ -z $Class ]; then
|
||||
|
Loading…
x
Reference in New Issue
Block a user