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 "obtain the currency lists... \n";
34 $response = $this->curl($this->actionUrl, array(), 'GET');
36 libxml_use_internal_errors (true);
38 $doc = new DOMDocument();
39 $doc->loadHTML($response);
41 libxml_use_internal_errors (false);
43 $xpath = new DOMXpath($doc);
45 $elements = $xpath->query("//select[@name='exch']/option");
47 foreach($elements as $el) {
48 $currency[] = $el->getAttribute('value');
52 die('no any currency');
58 // 'date1' => '10/14/14',
59 // 'date'=> '10/20/14',
60 // 'date_fmt' => 'us',
63 // 'margin_fixed' => 0,
67 // $response = $this->curl($this->actionUrl, $params, 'POST');
69 // file_put_contents('/tmp/test.html', $response);
73 function curl($url, $request = array(), $method = 'GET')
76 if(is_array($request)){
77 $request = http_build_query($request);
80 $url = $url . ($method == 'GET' ? "?" . $request : '');
81 $ch = curl_init($url);
83 if ($method == 'POST') {
84 curl_setopt($ch, CURLOPT_POST, 1);
85 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
86 curl_setopt($ch, CURLOPT_HTTPHEADER,
87 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
90 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
92 curl_setopt($ch, CURLOPT_HEADER, false);
93 curl_setopt($ch, CURLOPT_VERBOSE, 1);
94 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
95 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
97 $response = curl_exec($ch);