UpdateCurrencyRate.php
[Pman.Core] / UpdateCurrencyRate.php
1 <?php
2
3 require_once 'Pman.php';
4
5 class Pman_Core_UpdateCurrencyRate extends Pman
6 {
7     
8     static $cli_desc = "Update Currency Exchange Rate";
9     
10     static $cli_opts = array();
11     
12     var $cli = false; 
13     
14     var $actionUrl = 'http://www.oanda.com/currency/historical-rates-classic';
15     
16     
17     function getAuth() 
18     {
19         $ff = HTML_FlexyFramework::get();
20         if (!empty($ff->cli)) {
21             $this->cli = true;
22             return true;
23         }
24         
25         die("NOT ALLOWED");
26     }
27     
28     function get()
29     {
30         echo"'update currency exchange rate \n";
31         
32         $params = array(
33             'lang' => 'en',
34             'result' => 1,
35             'date1' => '10/14/14',
36             'date'=> '10/20/14',
37             'date_fmt' => 'us',
38             'exch' => 'CNY',
39 //            exch2:
40             'expr' => 'USD',
41 //            expr2:
42             'margin_fixed' => 0,
43             'format'=> 'HTML',
44 //            SUBMIT:Get Table
45         );
46         
47         $response = $this->curl($this->actionUrl, $params, 'POST');
48         
49         file_put_contents('/tmp/test.html', $response);
50         
51     }
52     
53     function curl($url, $request = array(), $method = 'GET') 
54     {
55          
56         if(is_array($request)){
57             $request = http_build_query($request);
58         }
59         
60         $url = $url . ($method == 'GET' ? "?" . $request : '');  
61         $ch = curl_init($url);
62         
63         if ($method == 'POST') {
64             curl_setopt($ch, CURLOPT_POST, 1);
65             curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
66             curl_setopt($ch, CURLOPT_HTTPHEADER,
67                     array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
68         }
69         
70         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
71         
72         curl_setopt($ch, CURLOPT_HEADER, false);
73         curl_setopt($ch, CURLOPT_VERBOSE, 1);
74         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
75         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
76
77         $response = curl_exec($ch);
78
79         curl_close($ch);
80         
81         return $response;
82     }
83     
84     /*
85     lang:en
86     result:1
87     date1:10/14/14
88     date:10/20/14
89     date_fmt:us
90     exch:USD
91     exch2:
92     expr:EUR
93     expr2:
94     margin_fixed:0
95     format:HTML
96     SUBMIT:Get Table
97     */
98 }