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 

Request: Script to get Crude oil & Precious metal spot p

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


Joined: 12 Aug 2007
Posts: 13

PostPosted: Sun Aug 12, 2007 12:25 pm    Post subject: Request: Script to get Crude oil & Precious metal spot p Reply with quote

Hello all, I was hoping someone could help me out and create a script that would retrieve the current Crude oil prices and precious metals. I tried writing a metals one myself, but I lack the knowledge to write the hard part. Here is what I tried:
Quote:

bind pubm - !metals get_metals

proc get_metals {nick uhost handle chan var} {
set query "http://genesiss.kitco.com/scripts/cgi-bin/texten.pl"
set token [http::geturl $query]
set all [http::data $token]

regexp {Gold(.*)Silver} $all - gold
regexp {Silver(.*)Platinum} $all - silver

putserv "PRIVMSG $chan :Gold: Bid: [linex $gold 0] Ask: [lindex $gold 1]"
putserv "PRIVMSG $chan :Silver: Bid: [linex $silver 0] Ask: [lindex $silver 1$


}

The website I want the gold and silver price from is http://genesiss.kitco.com/scripts/cgi-bin/texten.pl. Now, One problem I realized with my script, is there is 2 occurances of Gold and Silver before the spot where I want to grab the data from. I want to use the data from the New York Stock market for it. Since I couldn't get this one to work, I didn't even attempt the second. I was hoping the same thing could be done, to grab data from http://www.bloomberg.com/markets/commodities/energyprices.html and include the Price and change for Nymex Crude Future as well as Dated Brent spot.

Thank you so much for any and all help! Wink
_________________
irc://irc.efnet.net/peakoil
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Mon Aug 13, 2007 12:12 am    Post subject: Reply with quote

Well, if you look at any of the web scripts in the tcl archive, they would serve as a good template on which to base your script, as your example is lacking in a few places, but hey it's a good stab in the dark =)

You don't want to use pubm, you want to use a pub bind. Your regexp's are not precise enough to get the particular data you want.

For the new york gold/silver prices, I'd use something like:

Code:

if {[regexp {New York Spot Price.*?Gold.*? (\d+) (\d+) .*?Silver (\d+) (\d+)} $all match goldvar1 goldvar2 silvervar1 silvervar2]} {
           #do stuff with vars..
}


For the oil page:
Code:

if {[regexp {>Nymex Crude Future</span>.*?<span class="tbl_num">(.*?)</span>.*?>Dated Brent Spot</span>.*?<span class="tbl_num">(.*?)</span>.*?<span class="tbl_txt_green">(.*?)</span>} $all match nymexprice nymexchange brentprice brentchange]} {
        # do stuff

I'm not 100% certain about the regexp for the 1st set of numbers, but the 2nd for the oil stuff should work. Someone else might have more eloquent regexp examples Smile

And like I said, take a look at some other web scripts so you have a better idea of how to use geturl and such. Try again, we can help you make your own script (these webscripts are simple to make..I make tons of em.)
Back to top
View user's profile Send private message
pitbull
Voice


Joined: 12 Aug 2007
Posts: 13

PostPosted: Mon Aug 13, 2007 1:56 am    Post subject: Reply with quote

Thanks for your help. I managed to modify another script to get the metal prices using a loop. I couldn't get it to work for the oil prices, however, with your regexp example, I was able to modify my metals tcl and it almost worked. It was only picking up 3 variables with that expression, so I modified it a little and it got 4 like it was supposed to. I can't thank you enough for the help however Smile Smile Smile
_________________
irc://irc.efnet.net/peakoil
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