#!/bin/sh
while true; do
	TEMP=`crap/metar/metar KCXY |
		grep ^Observation: |
		sed -r '
			s,Observation: [^ ]+ ([0-9]+Z).*T([0-9]{4})([0-9]{4}).*,(at \1) Temp: \2C Dew: \3C [high prec],g;
			s,Observation: [^ ]+ ([0-9]+Z).* (M?[0-9]{2})/(M?[0-9]{2}).*,(at \1) Temp: 0\20C Dew: 0\30C [low prec],g;
			s@: 0M@: 1@g;
			s@: 10{0,2}([0-9][0-9])@: -\1@g;
			s@: 0{0,2}@: @g;
			s@: ([0-9-]+)([0-9])C@: \1.\2C@g
		'
	`
	echo $TEMP
	ALARM=`echo "$TEMP" |
		awk '{
			if (($4 + 0) <= -1.5) {
				print 1
			} else {
				print 0
			}
		}'
	`
	if [ "$ALARM" = "1" ]; then
		xmessage -center "Temperature warning\!
$TEMP"
	fi
	sleep 15m
done
