#!/bin/sh
# $Id: stockquote,v 1.3 2004-02-06 00:31:05 ianb-guest Exp $
# elvis: stockquote	-- Get a single stock quote (multiple providers)
. surfraw || exit 1

w3_config_hook () {
def   SURFRAW_stockquote_provider    yahoo
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] STOCK
Description:
  Surfraw fetch a single stock quote
Local options:
  -provider=    	        Quote provider to use
        yahoo			quote.yahoo.com
        nasdaq			nasdaq.com (InfoQuote)
        quote			quote.com
                		Default: $SURFRAW_stockquote_provider
                		Environment: SURFRAW_stockquote_provider
Examples:
  $w3_argv0                     Provider's standard quote page
  $w3_argv0 -provider=nasdaq    Use NASDAQ for quote
  $w3_argv0 BLDP                Obtain quote for 'Ballard Power'
EOF
    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
    -provider=*) setopt  SURFRAW_stockquote_provider $optarg    ;;
    *) return 1 ;;
    esac
    return 0
}

w3_config
w3_parse_args "$@"
# w3_args now contains a list of arguments
if test "$SURFRAW_stockquote_provider" = "yahoo"; then
    if test -z "$w3_args"; then
        w3_browse_url "http://quote.yahoo.com/"
    else
        escaped_args=`w3_url_of_arg $w3_args`
        w3_browse_url "http://quote.yahoo.com/q?s=${escaped_args}"
    fi
elif test "$SURFRAW_stockquote_provider" = "nasdaq"; then
    if test -z "$w3_args"; then
        w3_browse_url "http://www.nasdaq.com/"
    else
        escaped_args=`w3_url_of_arg $w3_args`
        w3_browse_url "http://quotes.nasdaq.com/Quote.dll?mode=Stock&symbol=${escaped_args}&symbol=&symbol=&symbol=&symbol=&symbol=&symbol=&symbol=&symbol=&symbol=&multi.x=44&multi.y=12"
    fi
elif test "$SURFRAW_stockquote_provider" = "quote"; then
    if test -z "$w3_args"; then
        w3_browse_url "http://www.quote.com/"
    else
        escaped_args=`w3_url_of_arg $w3_args`
        w3_browse_url "http://www.quote.com/quotecom/stocks/quotes.asp?symbols=${escaped_args}"
    fi
else
    err "-provider ${SURFRAW_stockquote_provider} unsupported"
fi
