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");
45 foreach($elements as $el) {
46 print_r($el->getAttribute('value'));
53 // 'date1' => '10/14/14',
54 // 'date'=> '10/20/14',
55 // 'date_fmt' => 'us',
58 // 'margin_fixed' => 0,
62 // $response = $this->curl($this->actionUrl, $params, 'POST');
64 // file_put_contents('/tmp/test.html', $response);
68 function curl($url, $request = array(), $method = 'GET')
71 if(is_array($request)){
72 $request = http_build_query($request);
75 $url = $url . ($method == 'GET' ? "?" . $request : '');
76 $ch = curl_init($url);
78 if ($method == 'POST') {
79 curl_setopt($ch, CURLOPT_POST, 1);
80 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
81 curl_setopt($ch, CURLOPT_HTTPHEADER,
82 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
85 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
87 curl_setopt($ch, CURLOPT_HEADER, false);
88 curl_setopt($ch, CURLOPT_VERBOSE, 1);
89 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
90 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
92 $response = curl_exec($ch);