[EDIT]This may be the wrong place for this - proceed at your own peril.
I do not do PHP, but I do cannibalize.

This is a little bit of code I’ve been trying to get together, but am way beyond my capability. Has anyone ever done this before? What I’d like to do is pull a csv file from Yahoo! Finance of the last 12months and output a graph with the information. So, the csv would have to be downloaded then converted to xml on the fly or something and fed to one of the JS graph utilities like PLOTR or PLOOTR (mootools). I’ve already found a good source, tested the download and put together some other resources, but can’t proceed. Here’s what I’ve been messing with so far, no yet ModX-ified:
<?php
Class yahoo
{
function get_stock_quote($symbol)
{
$url = sprintf("http://ichart.finance.yahoo.com/table.csv?s=$symbol&a=$month&b=$day&c=$year", $symbol);
$fp = fopen($url, 'r');
if (!fp) {
echo 'Error : cannot recieve stock quote data.';
} else {
$data = @fgetcsv($fp, 4096, ', ');
fclose($fp);
$this->symbol = $data[0]; // Stock symbol.
$this->last = $data[1]; // Last Trade (current price).
//$this->date = $data[2];
//$this->time = $data[3];
//$this->change = $data[4]; // + or - amount change.
//$this->open = $data[5];
//$this->high = $data[6];
//$this->low = $data[7];
//$this->volume = $data[8];
}
}
}
// This is the url to get the historical data http://ichart.finance.yahoo.com/table.csv?s=$ticker&a=$month&b=$day&c=$year
//s=$symbol (CGW)
//a=$month (year ago from today - in 00 format e.g., April = 04)
//b=$day (day or date in month e.g., 1 = 1st or 12 = 12th)
//c=$year (year from today - 2007)
// Stock symbols.
$symbols = array('AIG','CGW'); // These should be pulled automagically from the stock symbols in the modx database.
$i = 0;
// Variables would have to be automated somehow to go from today's date and set the variables for a year ago.
$month = array('01','02','03','04','05','06','07','08','09','10','11','12');
$day = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
$year = array('2007','2008','2009');
// Declare class.
$quote = new yahoo; // new stock.
// Loop thru array of symbols as a default display instead of a graph.
echo "<ul>\n";
foreach ($symbols as $symbol) {
$quote->get_stock_quote($symbols[$i++]); // Pass the Company's symbol.
echo "<li><a href=\"http://finance.yahoo.com/q?s=" .$symbol. "\" title=\"Yahoo! Finance: " .$symbol. "\">$quote->symbol</a>\n"; // can use $quote->symbol or $symbol
echo "<ul>\n";
echo "<li>Last Trade: \$" .$quote->last. "</li>\n"; // price.
echo '<li>Change: <span style="';
/* Make the + or - change elicit differing coloration. */
$str = $quote->change;
$first = $str{0};
if ($first == '+') { // If we gained print the # in GREEN.
echo 'color:#009900;';
} elseif ($first == '-') { // If we lost RED.
echo 'color:#990000;';
} else { // NO color.
echo 'font-weight:normal;';
} // endelseif
echo "\">" .$quote->change. "</span></li>\n";
echo "</ul>\n";
echo "</li>\n";
} // endforeach
echo "</ul>\n";
?>
Also, Jordan Boesch wrote a
script that could be used in conjunction with the above. It takes a csv file parses it and makes it ready to insert into a MySQL table. Here’s the parameters in the class:
$csv = new CSVData();
$csv->csvFile('file.csv'); // The path to our file (file.csv)
$csv->mysqlTable('tablename'); // The table we are dealing with
$csv->makeTable(false); // Do we want to make the table if its not created, you must declare the proper params in the .csv (true/false)
$csv->testMode(false); // If we want to test or just go in head first (true/false)
$csv->response(); // this returns true if the executed query worked. You can use an if statement to check this, followed by the error/success msg in the next param..
$csv->responseText(); // the error/success msg
I tried to comment it the best I could. Has anyone done this or something similar? FWIW, I am not asking anyone to write me a snippet or any other script. But, if you have experience with a similar task and wouldn’t mind sharing your strategy it would be much appreciated.