PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?PHP
- function pr($str){
- echo "<pre>";
- echo "</pre><br/>";
- }
- class Grabber{
- private $money_url = ''; //откуда грабим курсы валют
- private $oil_url = 'http://news.yandex.ru/quotes/1006.xml'; //откуда грабим котировки нефти
- private $save_path = ''; //в каком файле все храним
- private $oil = 0; //цена нефти
- public function __construct(){
- $this->money_url = 'http://www.cbr.ru/scripts/XML_daily.asp?date_req='.$date_str;
- $this->save_path = $_SERVER['DOCUMENT_ROOT'].'/money_grab/data.txt';
- $this->load_file();
- }
- public function get_oil(){
- return false;
- }
- return array( 'date'=>$this->upd_dates['oil']['day'].'.'.$this->upd_dates['oil']['month'].'.'.$this->upd_dates['oil']['year'],
- 'value'=>$this->oil);
- }
- public function get_currency($type='EUR'){
- return false;
- }
- return array( 'date'=>$this->upd_dates['money']['day'].'.'.$this->upd_dates['money']['month'].'.'.$this->upd_dates['money']['year'],
- 'value'=>$this->courses[$type]['value'],
- 'currency'=>$type,
- 'nominal'=>$this->courses[$type]['nominal']);
- }
- private function load_file(){
- if(!$handle){
- $this->remake_file();
- return false;
- }
- $buffer = "";
- }
- $this->remake_file();
- return false;
- }
- $this->remake_file();
- return false;
- }
- $this->upd_dates = $data['dates'];
- }
- $this->courses = $data['courses'];
- }
- $this->oil = $data['oil'];
- }
- return true;
- }
- public function remake_file(){
- $need2upd = false;
- $int_date_now = $this->date2int($this->upd_dates['money']);
- $new_data_money = $this->load_money();
- $int_date_money_new = $this->date2int($new_data_money['update']);
- if($int_date_now !==false and $int_date_money_new !==false and $int_date_money_new > $int_date_now){
- $need2upd = true;
- }
- }
- else{
- $need2upd = true;
- $new_data_money = $this->load_money();
- }
- $int_date_now = $this->date2int($this->upd_dates['oil']);
- $new_data_oil = $this->load_oil();
- $int_date_oil_new = $this->date2int($new_data_oil['update']);
- if($int_date_now !==false and $int_date_oil_new !==false and $int_date_oil_new > $int_date_now){
- $need2upd = true;
- }
- }
- else{
- $new_data_oil = $this->load_oil();
- $need2upd = true;
- }
- if($need2upd){
- $upd_content['dates']['money'] = $new_data_money['update'];
- $upd_content['dates']['oil'] = $new_data_oil['update'];
- $upd_content['courses'] = $new_data_money['data'];
- $upd_content['oil'] = $new_data_oil['data'];
- $this->upd_dates = $upd_content['dates'];
- $this->courses = $upd_content['courses'];
- $this->oil = $upd_content['oil'];
- }
- return true;
- }
- return false;
- }
- return false;
- }
- $int_val = $date['year']*365*24 + $date['month']*30*24 + $date['day']*24;
- $int_val += $date['hour'];
- }
- return $int_val;
- }
- private function load_money(){
- // $res = simplexml_load_file($this->money_url);
- $date_update = $res->xpath('/ValCurs/@Date');
- $date['day'] = $matches[1];
- $date['month'] = $matches[2];
- $date['year'] = $matches[3];
- }
- $return['update'] = $date;
- $list = $res->xpath('/ValCurs/Valute');
- foreach($list as $valute){
- }
- $return['data'] = $valutes;
- return $return;
- }
- private function load_oil(){
- // $res = simplexml_load_file($this->oil_url);
- $list = $res->xpath('/stock/sdt');
- $needed = $list[0];
- $date['day'] = $matches[3];
- $date['month'] = $matches[2];
- $date['year'] = $matches[1];
- $date['hour'] = $matches[1];
- }
- $return['update'] = $date;
- return $return;
- }
- private function curl_load($url=''){
- /* Пока прокси - оставим через курлы */
- return $result;
- }
- }
- ?>