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.

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

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
p
pitbull
Voice
Posts: 13
Joined: Sun Aug 12, 2007 12:12 pm

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

Post by pitbull »

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:
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/commod ... rices.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:
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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: Select all

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: Select all

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 :)

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.)
p
pitbull
Voice
Posts: 13
Joined: Sun Aug 12, 2007 12:12 pm

Post by pitbull »

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 :) :) :)
Post Reply