#!/bin/sh

# weather - Donne les prvisions mto ainsi que la latitude et la
#   longitude d'un code postal aux EU

llurl="http://www.census.gov/cgi-bin/gazetteer?city=&state=&zip="
wxurl="http://wwwa.accuweather.com"
wxurl="$wxurl/adcbin/public/local_index_print.asp?zipcode="

if [ "$1" = "-a" ] ; then
  size=999; shift
else 
  size=5
fi

if [ $# -eq 0 ] ; then
  echo "Syntaxe: $0 [-a] <code postal aux EU>" >&2
  exit 1
fi

if [ $size -eq 5 ] ; then
  echo ""

  # Cherche des informations sur ce code postal auprs des services
  #   du recensement.
  
  lynx -source "${llurl}$1" | \
    sed -n '/^<li><strong>/,/^Location:/p' | \
    sed 's/<[^>]*>//g;s/^ //g'
fi

# Les prvisions mto d'AccuWeather.com

lynx -source "${wxurl}$1" | \
  sed -n '/Start - Forecast Cell/,/End - Forecast Cell/p' | \
  sed 's/<[^>]*>//g;s/^ [ ]*//g' | \
  uniq | \
  head -$size

exit 0
