| 1 |
<?php |
<?php |
| 2 |
// $Id: stockapi.module,v 1.5.4.3 2007/06/25 23:45:29 kbahey Exp $ |
// $Id: stockapi.module,v 1.5.4.4 2007/10/26 04:01:20 kbahey Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 23 |
|
|
| 24 |
$items[] = array( |
$items[] = array( |
| 25 |
'path' => 'admin/settings/stockapi', |
'path' => 'admin/settings/stockapi', |
| 26 |
'title' => t('Stockapi settings'), |
'title' => t('Stock API settings'), |
| 27 |
'description' => t('Configure cron run settings.'), |
'description' => t('Configure cron run settings.'), |
| 28 |
'callback' => 'drupal_get_form', |
'callback' => 'drupal_get_form', |
| 29 |
'callback arguments' => array('stockapi_admin_settings'), |
'callback arguments' => array('stockapi_admin_settings'), |
| 69 |
} |
} |
| 70 |
variable_set('stockapi_fetch_last', time()); |
variable_set('stockapi_fetch_last', time()); |
| 71 |
cache_clear_all('variables', 'cache'); |
cache_clear_all('variables', 'cache'); |
| 72 |
watchdog('cron', t('Stock API updated OK')); |
watchdog('cron', t('Stock API updated.')); |
| 73 |
} |
} |
| 74 |
} |
} |
| 75 |
|
|
| 95 |
"t1" => "Time" |
"t1" => "Time" |
| 96 |
*/ |
*/ |
| 97 |
|
|
| 98 |
$host = 'http://finance.yahoo.com'; |
$host = 'http://download.finance.yahoo.com'; |
| 99 |
$url = $host .'/d/quotes.csv?s='. urlencode($symbol) .'&f='.$fields.'&e=.csv'; |
$url = $host .'/d/quotes.csv?s='. urlencode($symbol) .'&f='.$fields.'&e=.csv'; |
| 100 |
// Open the URL |
|
| 101 |
$fd = fopen($url, "r"); |
$result = drupal_http_request($url); |
| 102 |
if (!$fd) { |
if (isset($result->error)) { |
| 103 |
|
watchdog('stockapi', t('StockAPI: drupal_http_request error: @error', array('@error' => $result->error))); |
| 104 |
return FALSE; |
return FALSE; |
| 105 |
} |
} |
|
// Process the CSV data correctly |
|
|
$data = fgetcsv($fd, 1024); |
|
| 106 |
|
|
| 107 |
fclose($fd); |
if ($result->code != 200) { |
| 108 |
if (!$data) { |
watchdog('stockapi', t('StockAPI: drupal_http_request code: @code', array('@code' => $result->code))); |
| 109 |
return FALSE; |
return FALSE; |
| 110 |
} |
} |
| 111 |
|
|
| 112 |
|
$data = explode(',', str_replace('"', '', $result->data)); |
| 113 |
|
if (!$data) { |
| 114 |
|
watchdog('stockapi', t('StockAPI: no data for symbol(s): @symbol', array('@symbol' => $symbol))); |
| 115 |
|
return FALSE; |
| 116 |
|
} |
| 117 |
|
|
| 118 |
$data = array_map('trim', $data); |
$data = array_map('trim', $data); |
| 119 |
return $data; |
return $data; |
| 120 |
} |
} |