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';
22 $ff = HTML_FlexyFramework::get();
23 if (!empty($ff->cli)) {
33 echo "obtain the currency lists... \n";
37 $response = $this->curl($this->actionUrl, array(), 'GET');
39 libxml_use_internal_errors (true);
41 $doc = new DOMDocument();
42 $doc->loadHTML($response);
44 libxml_use_internal_errors (false);
46 $xpath = new DOMXpath($doc);
48 $elements = $xpath->query("//select[@name='exch']/option");
50 foreach($elements as $el) {
51 $currency[] = $el->getAttribute('value');
55 die('no any currency');
58 foreach ($currency as $c){
62 'date1' => '10/14/14',
63 'date'=> date('m/d/y'),
78 // 'date1' => '10/14/14',
79 // 'date'=> '10/20/14',
80 // 'date_fmt' => 'us',
83 // 'margin_fixed' => 0,
87 // $response = $this->curl($this->actionUrl, $params, 'POST');
89 // file_put_contents('/tmp/test.html', $response);
93 function curl($url, $request = array(), $method = 'GET')
96 if(is_array($request)){
97 $request = http_build_query($request);
100 $url = $url . ($method == 'GET' ? "?" . $request : '');
101 $ch = curl_init($url);
103 if ($method == 'POST') {
104 curl_setopt($ch, CURLOPT_POST, 1);
105 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
106 curl_setopt($ch, CURLOPT_HTTPHEADER,
107 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
110 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
112 curl_setopt($ch, CURLOPT_HEADER, false);
113 curl_setopt($ch, CURLOPT_VERBOSE, 1);
114 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
115 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
117 $response = curl_exec($ch);