This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Stock quotes

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
s
start
Voice
Posts: 2
Joined: Fri Feb 13, 2009 5:11 pm

Stock quotes

Post by start »

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.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Code: Select all

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
}
Image

SELL SELL SELL!!!
I must have had nothing to do
m
marx2k
Voice
Posts: 10
Joined: Sun Jan 23, 2011 10:34 am

Post by marx2k »

This does not seem to function any longer. Could this be updated to work again? Would be great.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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.
m
marx2k
Voice
Posts: 10
Joined: Sun Jan 23, 2011 10:34 am

Post by marx2k »

I did as you suggested.

I got:

Code: Select all

 Tcl error [prcMarketCommand]: can't read "data": no such variable
Here's what the script looks like right now:

Code: Select all

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
}
Post Reply