Forum Moderators: coopster

Message Too Old, No Replies

Altering currency conversion tool

I want to adapt this great free program

         

kahunaschooner

1:32 am on Oct 9, 2008 (gmt 0)

10+ Year Member



Hi,

I am using this great free program (and he has disabled his contact form.

<snip>

daily this pulls an .xml file of a website then converts it to create an exchange rate for a site I am working on. the .xml file is then stored locally.

I want to limit that down load to occur weekly or even monthly, so I can have another set of data which is not dynamically created to be using the same exchange rate.

The relevant piece of code is -

function getData(){
$olderr=error_reporting(0);
$this->Source="Local";
if(file_exists($this->localFile)){
// load it
$this->xml=@file_get_contents($this->localFile);
$this->parse();

// check if it's a weekend
// what day of the week is it?
$weekday=date("w");
// if it's a Sunday or Saturday
if($weekday==0 ¦¦ $weekday==6){
// go back to last Friday
$date=date("Y-m-d",strtotime("last Friday"));
} else {
$date=date("Y-m-d");
}
// if the date in the local file is not the same
// as our current date, or last Friday for weekends
if($this->Date!=$date ){
// get the remote file
if(strlen($this->getRemoteFile($this->url)) > 10)
{
$this->clearData();
$this->xml=$this->getRemoteFile($this->url);
$this->Source="Remote";
// write the remote file data to a local copy of the file
$this->saveLocalCopy();
}
} // if we have a local copy
}else{
$this->xml=$this->getRemoteFile($this->url);

if($this->xml)
// write the remote file data to a local copy of the file
$this->saveLocalCopy();
}
if(!$this->xml)
$this->error="Failed to get data";
else{
$this->parse();
}

Just wondering if it is possible to specify a day and time in a given month or day of a week to only downlaod the remote .xml file (which incidentally comes from the European central bank)

Regards,

Kahuna

[edited by: dreamcatcher at 7:17 am (utc) on Oct. 9, 2008]
[edit reason] No urls please! [/edit]

mrscruff

7:46 am on Oct 9, 2008 (gmt 0)

10+ Year Member



could try this:

j - days 1-31, G - hours 0-23, so example would run on 1st of every month, at 3am. For this to work the script would have to be called within the hour.

if (date('j G') == '1 3') {
//code goes here
}

May be better to just run a cron/scheduled task that runs a script to update the file rather than relying on user being on the site at the right time to activate the script.