CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
simple stock quote script

 



flanman
Novice

Dec 4, 2000, 2:54 PM

Post #1 of 3 (707 views)
simple stock quote script Can't Post

Hi,
I am looking for a simple script that will fetch just one stock quote, for my company, and embed the info into my home html page. An example would be like when you go to a finance site and you automatically get the indexes (NYSE,Nasdaq) on the page. I want to be able to do that with my companies stock symbol, ADP. I do not care about high,lows, volume etc, just the current price. I have implemented several prewritten cgi scripts on our site, but have little to no knowledge on how to create them from scratch. I will greatly appreciate any help that is offered. I have seen java/cgi scripts where a user types in the symbol and gets the info, but I want that part to be automatic when the whole page loads.

Thanks,
Bill Flanagan


liox0001
Deleted

Dec 7, 2000, 7:02 PM

Post #2 of 3 (707 views)
Re: simple stock quote script [In reply to] Can't Post

you can just modified the cgi script you mentioned to default the stock quote to the one you want (ie. default the quote and skip the input part).


jeffee
Deleted

Dec 8, 2000, 3:30 PM

Post #3 of 3 (707 views)
Re: simple stock quote script [In reply to] Can't Post

Here is a simple script that should do the trick. Just change the hardcoded ticker in here (altr) to whatever ticker you want. This is basically just using LWP::Simple with a decimal formatted quote from Motley Fool. Note, I chose to do the formatting of the HTML myself here; there are a lot of HTML formatting modules on CPAN you may want to check into as well.

#!/usr/bin/perl
use CGI;
use LWP::Simple;

my $page = new CGI();
print $page->header();
print $page->start_html("Welcome page");
my $ticker = 'altr'; # change this to yours
print "The current price of $ticker is " ,
&GetLatestPrice($ticker) , "\n";
print $page->end_html();

sub GetLatestPrice
{
my($ticker) = shift | | return;
$ticker = uc($ticker);
my($page)="http://quote.fool.com/" .
"detailed.asp?symbols=" .
"${ticker}&Format=Decimal";
my $text = &FormatPage(get($page));
if($text =~ /\nPrice.*\n([\d\.]+)/m)
{
return $1;
}
return;
}

sub FormatPage
{
my($text) = @_;
$text =~ s/\r//mgi;
$text =~ s/<\s*br[^>]*>/\n/mgi;
$text =~ s/<\s*p[^>]*>/\n/mgi;
$text =~ s/<\s*td[^>]*>/\t/mgi;
$text =~ s/<\s*tr[^>]*>/\n/mgi;
$text =~ s/<[^>]*>//mgi;
$text =~ s/\n+/\n/mgi;
return $text;
}



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives