egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Stock quotes

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
start
Voice


Joined: 13 Feb 2009
Posts: 2

PostPosted: Wed Mar 04, 2009 9:37 pm    Post subject: Stock quotes Reply with quote

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
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sun Mar 08, 2009 8:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
marx2k
Voice


Joined: 23 Jan 2011
Posts: 10

PostPosted: Tue Apr 26, 2011 10:52 am    Post subject: Reply with quote

This does not seem to function any longer. Could this be updated to work again? Would be great.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Tue Apr 26, 2011 2:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
marx2k
Voice


Joined: 23 Jan 2011
Posts: 10

PostPosted: Sat Apr 30, 2011 4:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber