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');
34 file_put_contents('/tmp/test.html', $response);
36 $doc = new DOMDocument();
37 $doc->loadHTMLFile('/tmp/test.html');
39 $xpath = new DOMXpath($doc);
41 $elements = $xpath->query("/html/body/select[@name='exch']");
43 foreach($elements as $el) {
51 // 'date1' => '10/14/14',
52 // 'date'=> '10/20/14',
53 // 'date_fmt' => 'us',
56 // 'margin_fixed' => 0,
60 // $response = $this->curl($this->actionUrl, $params, 'POST');
62 // file_put_contents('/tmp/test.html', $response);
66 function curl($url, $request = array(), $method = 'GET')
69 if(is_array($request)){
70 $request = http_build_query($request);
73 $url = $url . ($method == 'GET' ? "?" . $request : '');
74 $ch = curl_init($url);
76 if ($method == 'POST') {
77 curl_setopt($ch, CURLOPT_POST, 1);
78 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
79 curl_setopt($ch, CURLOPT_HTTPHEADER,
80 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
83 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
85 curl_setopt($ch, CURLOPT_HEADER, false);
86 curl_setopt($ch, CURLOPT_VERBOSE, 1);
87 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
88 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
90 $response = curl_exec($ch);