Category: | Utility / Web |
Author/Contact Info | scribe@ziplip.com |
Description: | Retrieves basic stock quotes from yahoo. Uses IO::Socket to connect to webserver. Can only retrieve one quote at a time now. Sample output: (( ELON 51.625 -3.5625 ) ( 49 -- 56.5 ) ( Vol: 1646200 )) |
#!/usr/bin/perl -w # Steven Rutter <scribe@ziplip.com> use IO::Socket; use strict; if ($#ARGV < 0) { die "usage: $0 <symbol>\n" } my $symbol = $ARGV[0]; my $server = 'quote.yahoo.com'; my $serverPort = '80'; my $get = "/d/quotes.cgi?s=$symbol&f=sl1d1t1c1ohgv&e=.csv"; my $remote = new IO::Socket::INET ( Proto=>'tcp', PeerAddr=>$server, PeerPort=>$serverPort, Reuse=>1 ) or die $!; $remote -> autoflush(1); print $remote "GET $get HTTP/1.0\n\n"; my $quote; while ( my $raw = <$remote>) { # "USVOE.OB",2.75,"4/12/2000","4:00PM",-0.3125,3.0625,3.160000,2.656 +25,538100 # symb, price, lastTrade, lastTradeTime, change, high, low, volume if ( $raw =~ /\"/ ) { $quote = $raw; } } close $remote; $quote =~ s/\"//g; $quote =~ s/^M//g; chomp $quote; my @qarray = split(/,/, $quote); print "(( $qarray[0] $qarray[1] $qarray[4] ) ( $qarray[7] -- $qarray[ +6] ) ( Vol: $qarray[8] ))\n"; |
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: Stock Quotes
by KM (Priest) on May 24, 2000 at 20:57 UTC | |
by KM (Priest) on May 24, 2000 at 23:30 UTC | |
by Elliott (Pilgrim) on Oct 10, 2001 at 19:53 UTC | |
by dragonchild (Archbishop) on Oct 10, 2001 at 20:02 UTC | |
by ZZamboni (Curate) on May 25, 2000 at 01:51 UTC | |
by perlmonkey (Hermit) on May 25, 2000 at 07:52 UTC | |
Re: Stock Quotes
by mga (Initiate) on Mar 07, 2001 at 20:11 UTC |