Hi there I have made a slight mention of the above issue in the past here. I have setup a views block to display the top 5 mostly converted currencies in my country and am hoping to find a way to have the values refresh to the current day without a manual conversion being done. Is there any way to accomplish this? Maybe a trigger upon cron run or something similar would be good. Please advise.

Regards

Comments

amateescu’s picture

Status: Active » Fixed

You can implement hook_cron() in a custom module and call currency_api_convert() in there for each of your desired currencies.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

vensires’s picture

Just for the reference, I created a currency_profile module for use in my company's clients' profiles and since I needed daily updated information I also wrote the following function:

/*
 * Fix for the Currency Profile module to get values
 * from Yahoo on cron run instead of form submition!
 */
function currency_profile_cron(){
  $list = array_keys(currency_api_get_list());  //retrieve currency list
  sort($list);
  $from = variable_get('uc_currency_code','EUR'); //load the site currency
  $amount = 1;  //change 1 EUR to ...
  $currency_array = array(
    's'  => 'Currencies',
    'l1' => 'Last',
    'd1' => 'Date',
    't1' => 'Time'
  );
  foreach($list as $key=>$to){
    $url = 'http://download.finance.yahoo.com/d/quotes.csv?e=.csv&f='. currency_api_get_fields($currency_array) .'&s='. $from . $to .'=X';
    watchdog('currency_profile',$url);
    $http_result = drupal_http_request($url);
    if (isset($http_result->error)) {
      $msg = t('currency: drupal_http_request error: @error', array('@error' => $http_result->error));
      currency_log($msg, WATCHDOG_ERROR);
      return FALSE;
    }
    if ($http_result->code != 200) {
      $msg = t('currency: drupal_http_request code: @code', array('@code' => $http_result->code));
      currency_log($msg, WATCHDOG_ERROR);
      return FALSE;
    }
    $record = $http_result->data;
    if (!$record) {
      $msg = t('currency: cannot contact Yahoo Finance host');
      currency_log($msg, WATCHDOG_ERROR);
    } else {
      $currency_data = explode(',', $record);
      $rate = $currency_data[1];
      $date = $currency_data[2];
      $time = $currency_data[3];
      $timestamp = strtotime(str_replace('"', '', $date) . ' ' . str_replace('"', '', $time));
      currency_api_save($from, $to, $rate);
    }
  }
}

It may not be a solution completely ready to be included in the Currency Exchange core, but it sure did the work for me and may be a good start for other needing to implement this in their sites.