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 print_r(date('m/d/y'));exit;
35 echo "obtain the currency lists... \n";
39 $response = $this->curl($this->actionUrl, array(), 'GET');
41 libxml_use_internal_errors (true);
43 $doc = new DOMDocument();
44 $doc->loadHTML($response);
46 libxml_use_internal_errors (false);
48 $xpath = new DOMXpath($doc);
50 $elements = $xpath->query("//select[@name='exch']/option");
52 foreach($elements as $el) {
53 $currency[] = $el->getAttribute('value');
57 die('no any currency');
60 // foreach ($currency as $c){
64 // 'date1' => '10/14/14',
65 // 'date'=> date('m/d/y'),
66 // 'date_fmt' => 'us',
69 // 'margin_fixed' => 0,
80 // 'date1' => '10/14/14',
81 // 'date'=> '10/20/14',
82 // 'date_fmt' => 'us',
85 // 'margin_fixed' => 0,
89 // $response = $this->curl($this->actionUrl, $params, 'POST');
91 // file_put_contents('/tmp/test.html', $response);
95 function curl($url, $request = array(), $method = 'GET')
98 if(is_array($request)){
99 $request = http_build_query($request);
102 $url = $url . ($method == 'GET' ? "?" . $request : '');
103 $ch = curl_init($url);
105 if ($method == 'POST') {
106 curl_setopt($ch, CURLOPT_POST, 1);
107 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
108 curl_setopt($ch, CURLOPT_HTTPHEADER,
109 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
112 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
114 curl_setopt($ch, CURLOPT_HEADER, false);
115 curl_setopt($ch, CURLOPT_VERBOSE, 1);
116 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
117 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
119 $response = curl_exec($ch);