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');
55 print_r($currency);exit;
59 // 'date1' => '10/14/14',
60 // 'date'=> '10/20/14',
61 // 'date_fmt' => 'us',
64 // 'margin_fixed' => 0,
68 // $response = $this->curl($this->actionUrl, $params, 'POST');
70 // file_put_contents('/tmp/test.html', $response);
74 function curl($url, $request = array(), $method = 'GET')
77 if(is_array($request)){
78 $request = http_build_query($request);
81 $url = $url . ($method == 'GET' ? "?" . $request : '');
82 $ch = curl_init($url);
84 if ($method == 'POST') {
85 curl_setopt($ch, CURLOPT_POST, 1);
86 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
87 curl_setopt($ch, CURLOPT_HTTPHEADER,
88 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
91 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
93 curl_setopt($ch, CURLOPT_HEADER, false);
94 curl_setopt($ch, CURLOPT_VERBOSE, 1);
95 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
96 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
98 $response = curl_exec($ch);