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 $doc = new DOMDocument();
35 $doc->loadHTML($response);
37 $xpath = new DOMXpath($doc);
39 $elements = $xpath->query("//select[@name='exch']/option");
41 foreach($elements as $el) {
49 // 'date1' => '10/14/14',
50 // 'date'=> '10/20/14',
51 // 'date_fmt' => 'us',
54 // 'margin_fixed' => 0,
58 // $response = $this->curl($this->actionUrl, $params, 'POST');
60 // file_put_contents('/tmp/test.html', $response);
64 function curl($url, $request = array(), $method = 'GET')
67 if(is_array($request)){
68 $request = http_build_query($request);
71 $url = $url . ($method == 'GET' ? "?" . $request : '');
72 $ch = curl_init($url);
74 if ($method == 'POST') {
75 curl_setopt($ch, CURLOPT_POST, 1);
76 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
77 curl_setopt($ch, CURLOPT_HTTPHEADER,
78 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
81 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
83 curl_setopt($ch, CURLOPT_HEADER, false);
84 curl_setopt($ch, CURLOPT_VERBOSE, 1);
85 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
86 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
88 $response = curl_exec($ch);