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 $doc = new DOMDocument();
37 $doc->loadHTML($response);
39 $xpath = new DOMXpath($doc);
41 $elements = $xpath->query("//select[@name='exch']/option");
43 foreach($elements as $el) {
44 $currency[] = $el->getAttribute('value');
48 die('no any currency');
54 // 'date1' => '10/14/14',
55 // 'date'=> '10/20/14',
56 // 'date_fmt' => 'us',
59 // 'margin_fixed' => 0,
63 // $response = $this->curl($this->actionUrl, $params, 'POST');
65 // file_put_contents('/tmp/test.html', $response);
69 function curl($url, $request = array(), $method = 'GET')
72 if(is_array($request)){
73 $request = http_build_query($request);
76 $url = $url . ($method == 'GET' ? "?" . $request : '');
77 $ch = curl_init($url);
79 if ($method == 'POST') {
80 curl_setopt($ch, CURLOPT_POST, 1);
81 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
82 curl_setopt($ch, CURLOPT_HTTPHEADER,
83 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
86 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
88 curl_setopt($ch, CURLOPT_HEADER, false);
89 curl_setopt($ch, CURLOPT_VERBOSE, 1);
90 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
91 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
93 $response = curl_exec($ch);