| View previous topic :: View next topic |
| Author |
Message |
start Voice
Joined: 13 Feb 2009 Posts: 2
|
Posted: Wed Mar 04, 2009 9:37 pm Post subject: Stock quotes |
|
|
Hello,
I need something more specific than the current stock scripts on the archive. The scripts that are available now only show one index at a time. Example:
<user> !dow
<bot> (Down Jones) 6800 -100 | 3/4/2009
I would like to display three indexes like so...
<user> !us
<bot> (Dow Jones 6800 -100 2%) (Nasdaq 2000 -100 5.3%) (S&P 700 -20 1.3%)
I would also like to display percentage loss and gains. Lastly, I noticed the other scripts have if and else conditions to display the numbers that are positive are green and negative numbers are red. |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Sun Mar 08, 2009 8:00 pm Post subject: |
|
|
| Code: |
package require http
bind PUB n !market prcMarketCommand
proc prcMarketCommand {nick uhost hand chan text} {
set url http://www.londonstockexchange.com/en-gb/home.htm
set agent [::http::config -useragent "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"]
set token [::http::geturl $url -timeout 10000]
switch -- [::http::status $token] {
"timeout" {putserv "PRIVMSG $chan :-error- http operation (timed out)"}
"error" {putserv "PRIVMSG $chan :-error- http error ([::http::error $token])"}
"ok" {
switch -- [http::ncode $token] {
200 {
set rise \00303[encoding convertto utf-8 \u25B2]\003; set fall \00304[encoding convertto utf-8 \u25BC]\003
set same \00312[encoding convertto utf-8 \u25BA]\003; set lost \00307[encoding convertto utf-8 \u25CF]\003
regexp -- {\<MARQUEE(.+?)\</MARQUEE} [::http::data $token] match data
regsub -all -- {[\n\r]} $data ""
array set identity {
ftse "FTSE 100" dow "Dow Jones IA" nasdaq "NASDAQ 100"
dax "DAX Index" cac "CAC 40 Index" nikkei "Nikkei Index"
}
set pattern \<b\>\[\\s\]\(\[^\<\]\+?\)\</b\>\[\\s\]\<b\>\<\[^\>\]\+\>\(\[^\<\]\+?\)\</font\>
foreach market [array names identity] {
regexp -- [subst -nocommands -nobackslashes {$identity($market)$pattern}] $data match price($market) change($market)
if {([info exists price($market)]) && ([info exists change($market)])} {
switch -- [string index $change($market) 0] {
\+ {putserv "PRIVMSG $chan :$identity($market) $rise $price($market) $change($market)"}
\- {putserv "PRIVMSG $chan :$identity($market) $fall $price($market) $change($market)"}
default {putserv "PRIVMSG $chan :$identity($market) $same $price($market) $change($market)"}
}
} else {putserv "PRIVMSG $chan :$identity($market) $lost data unavailable"}
}
}
default {putserv "PRIVMSG $chan :-error- http ncode ([http::ncode $token])"}
}
}
}
return 0
}
|
SELL SELL SELL!!! _________________ I must have had nothing to do |
|
| Back to top |
|
 |
marx2k Voice
Joined: 23 Jan 2011 Posts: 10
|
Posted: Tue Apr 26, 2011 10:52 am Post subject: |
|
|
| This does not seem to function any longer. Could this be updated to work again? Would be great. |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Apr 26, 2011 2:10 pm Post subject: |
|
|
The url (the 'set url' line) has changed thus why it's no longer working. Tried changing it to current main address? _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
marx2k Voice
Joined: 23 Jan 2011 Posts: 10
|
Posted: Sat Apr 30, 2011 4:22 pm Post subject: |
|
|
I did as you suggested.
I got:
| Code: | | Tcl error [prcMarketCommand]: can't read "data": no such variable |
Here's what the script looks like right now:
| Code: | package require http
bind PUB n !market prcMarketCommand
proc prcMarketCommand {nick uhost hand chan text} {
set url http://www.londonstockexchange.com/home/homepage.htm
set agent [::http::config -useragent "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"]
set token [::http::geturl $url -timeout 10000]
switch -- [::http::status $token] {
"timeout" {putserv "PRIVMSG $chan :-error- http operation (timed out)"}
"error" {putserv "PRIVMSG $chan :-error- http error ([::http::error $token])"}
"ok" {
switch -- [http::ncode $token] {
200 {
set rise \00303[encoding convertto utf-8 \u25B2]\003; set fall \00304[encoding convertto utf-8 \u25BC]\003
set same \00312[encoding convertto utf-8 \u25BA]\003; set lost \00307[encoding convertto utf-8 \u25CF]\003
regexp -- {\<MARQUEE(.+?)\</MARQUEE} [::http::data $token] match data
regsub -all -- {[\n\r]} $data ""
array set identity {
ftse "FTSE 100" dow "Dow Jones IA" nasdaq "NASDAQ 100"
dax "DAX Index" cac "CAC 40 Index" nikkei "Nikkei Index"
}
set pattern \<b\>\[\\s\]\(\[^\<\]\+?\)\</b\>\[\\s\]\<b\>\<\[^\>\]\+\>\(\[^\<\]\+?\)\</font\>
foreach market [array names identity] {
regexp -- [subst -nocommands -nobackslashes {$identity($market)$pattern}] $data match price($market) change($market)
if {([info exists price($market)]) && ([info exists change($market)])} {
switch -- [string index $change($market) 0] {
\+ {putserv "PRIVMSG $chan :$identity($market) $rise $price($market) $change($market)"}
\- {putserv "PRIVMSG $chan :$identity($market) $fall $price($market) $change($market)"}
default {putserv "PRIVMSG $chan :$identity($market) $same $price($market) $change($market)"}
}
} else {putserv "PRIVMSG $chan :$identity($market) $lost data unavailable"}
}
}
default {putserv "PRIVMSG $chan :-error- http ncode ([http::ncode $token])"}
}
}
}
return 0
}
|
|
|
| Back to top |
|
 |
|