Paste: get yahoo taiwan exchange info
Author: | cataska |
Mode: | factor |
Date: | Thu, 26 Mar 2009 03:15:14 |
Plain Text |
USING: formatting http.client sequences strings kernel io math regexp
unicode.case assocs ;
IN: currency
: coins
{
"TWD" "CNY" "JPY" "KRW"
"HKD" "THB" "SGD" "IDR"
"VND" "MYR" "PHP" "INR"
"AED" "KWD" "AUD" "NZD"
"USD" "CAD" "BRL" "MXN"
"ARS" "CLP" "VEB" "EUR"
"GBP" "RUB" "CHF" "SEK"
"ZAR"
} ;
: coins?
coins member? ;
: calias
H{
{ "NTD" "TWD" }
{ "RMB" "CNY" }
} ;
: calias?
calias keys member? ;
: calias-at
dup calias? [ calias at ] [ drop f ] if ;
: yahootw-url
"http://tw.money.yahoo.com/currency_exc_result?amt=%d&from=%s&to=%s" ;
: div-tag
" <div class" ;
: make-url
yahootw-url sprintf ;
: strip-em-tag
R! </?em>! "" re-replace ;
: find-exchange
"經過計算後," over start 7 + cut div-tag over start 0 spin subseq strip-em-tag nip ;
: get-ex-money
[ >upper ] bi@ 2dup [
coins?
] bi@
and [ make-url http-get nip find-exchange ]
[ 3drop f ] if ;
New Annotation