Closed (fixed)
Project:
Stock
Version:
4.6.x-1.x-dev
Component:
User interface
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
2 Jun 2005 at 05:54 UTC
Updated:
16 Jun 2005 at 23:15 UTC
After setting up the "Stock" module on my Drupal site, I realized that when looking at the page at the admin page/form (http://drupal-site-host-name.com/?q=stock) it was difficult to tell which stock was which unless you had the ticker symbols memorized.
I was able to play around with some of the code in the "stock_do_quotes" function of the file "stock.module" and found a way to display the company names on the aforementioned page.
First, let's look at how to get the company name from Yahoo:
/*
Get a Stock Quote via Yahoo CSV facility
The URL is
http://finance.yahoo.com/d/quotes.csv?e=.csv&f=snl1d1t1c1ohgv&symbol= // Changed by SLACK1661
s Symbol
n Name // Added by SLACK1661
l1 Current Price
d1 Day (American Fmt mm/dd/yyyy)
t1 Time (h:mmPM)
c1 Change
o Opening Price
h High
g Low
v Volume
The result is as follows:
"VZ","VERIZON COMMUN",35.36,"6/1/2005","4:02pm",-0.02,35.50,35.555,35.20,7125300 // Added by SLACK1661
"RHAT",256,"1/5/2000","4:00PM",+41,218.5,258,212,2331300
"NCR",37.25,"1/5/2000","4:01PM",-0.375,37.6875,37.75,36.5625,844300
"COMS",44.0625,"1/5/2000","4:01PM",-1.9375,45.3125,45.875,43,6950800
"CPQ",28.5,"1/5/2000","6:29PM",-0.5,28.5625,30.25,27.125,29190600
*/
Now for a copy of the "stock_do_quotes" function with the changes I made commented.
function stock_do_quote( $format = 'long', $symbol_list )
{
$stock_long_array = array
(
"s" => "Symbol",
// The following 1 line was added by SLACK1661
"n" => "Company/Index Name",
"l1" => "Last",
"d1" => "Date",
"t1" => "Time",
"c1" => "Change",
"o" => "Opening",
"h" => "High",
"g" => "Low",
"v" => "Volume"
);
$stock_short_array = array
(
"s" => "Symbol",
"l1" => "Last",
"c1" => "Change"
);
switch ( $format )
{
case 'long':
$stock_array = $stock_long_array;
break;
case 'short':
$stock_array = $stock_short_array;
break;
}
$host = "finance.yahoo.com";
$url = "http://". $host ."/d/quotes.csv?e=.csv&f=". stock_get_fields($stock_array) ."&symbol=";
$result = "<table>";
$headers = stock_get_headers( $stock_array );
$result .= stock_print_header ( $headers );
// Convert the space separated list of symbols into an array
//$symbol_array = explode (" ", trim($symbol_list) );
$symbol_str = str_replace ( " ", "+", trim ($symbol_list) );
if ( $symbol_list )
{
$stock_url = $url . $symbol_str;
$handle = @fopen ( $stock_url, "r" );
if ( $handle )
{
while ( true )
{
$record = fgets ( $handle, 1024 );
//print "<!-- stock_do_quote() record=$record -->";
$stock_data = explode (",", $record);
$result .= stock_print_data ( $stock_data, $headers );
if ( true == feof( $handle ) )
{
break;
}
}
fclose ( $handle );
}
else
{
$result .= t("Could not contact host: ") . $url;
}
}
$result .= "</table>";
return $result;
}
Please drop me a line if further explanation is needed.
Comments
Comment #1
kbahey commentedGood idea. Added it.
Comment #2
(not verified) commented