3 require_once 'Pman.php';
5 class Pman_Core_UpdateCurrencyRate extends Pman
8 static $cli_desc = "Update Currency Exchange Rate";
10 static $cli_opts = array();
14 var $actionUrl = 'http://www.oanda.com/currency/historical-rates-classic';
19 $ff = HTML_FlexyFramework::get();
20 if (!empty($ff->cli)) {
30 echo"'update currency exchange rate \n";
32 $response = $this->curl($this->actionUrl, array(), 'GET');
33 file_put_contents('/tmp/test.html', $response);exit;
36 $doc = new DOMDocument();
37 $doc->loadHTML($response);
39 $xpath = new DOMXpath($doc);
44 // 'date1' => '10/14/14',
45 // 'date'=> '10/20/14',
46 // 'date_fmt' => 'us',
49 // 'margin_fixed' => 0,
53 // $response = $this->curl($this->actionUrl, $params, 'POST');
55 // file_put_contents('/tmp/test.html', $response);
59 function curl($url, $request = array(), $method = 'GET')
62 if(is_array($request)){
63 $request = http_build_query($request);
66 $url = $url . ($method == 'GET' ? "?" . $request : '');
67 $ch = curl_init($url);
69 if ($method == 'POST') {
70 curl_setopt($ch, CURLOPT_POST, 1);
71 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
72 curl_setopt($ch, CURLOPT_HTTPHEADER,
73 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
76 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
78 curl_setopt($ch, CURLOPT_HEADER, false);
79 curl_setopt($ch, CURLOPT_VERBOSE, 1);
80 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
81 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
83 $response = curl_exec($ch);