Example #1
0
 public static function run()
 {
     $data['feedurl'][] = file_get_contents('http://headlines.yahoo.co.jp/rss/goal-c_spo.xml');
     $data['feedurl'][] = file_get_contents('http://headlines.yahoo.co.jp/rss/gekisaka-c_spo.xml');
     $data['feedurl'][] = file_get_contents('http://zasshi.news.yahoo.co.jp/rss/soccermzw-all.xml');
     $data['feedurl'][] = file_get_contents('http://zasshi.news.yahoo.co.jp/rss/footballc-all.xml');
     $data['feedurl'][] = file_get_contents('http://zasshi.news.yahoo.co.jp/rss/fballista-all.xml');
     $data['feedurl'][] = file_get_contents('http://www.nikkansports.com/soccer/world/atom.xml');
     $data['feedurl'][] = file_get_contents('http://rss.rssad.jp/rss/number/jfootball');
     $data['feedurl'][] = file_get_contents('http://rss.rssad.jp/rss/number/wfootball');
     $data['feedurl'][] = file_get_contents('http://www.soccer-king.jp/RSS.rdf');
     $data['feedurl'][] = file_get_contents('http://murayaman.blog72.fc2.com/?xml');
     $kaisya = array('GOAL - スポーツ - Yahoo!ニュース', 'ゲキサカ - スポーツ - Yahoo!ニュース', 'Soccer Magazine ZONE web - 雑誌 - Yahoo!ニュース', 'フットボールチャンネル - 雑誌 - Yahoo!ニュース', 'footballista - 雑誌 - Yahoo!ニュース', '海外サッカー - nikkansports.com', 'サッカー日本代表 - Number Web', '海外サッカー - Number Web', 'サッカーキング - ニュース', '村山義光ライブスケジュール・ブログ');
     $count = count($data['feedurl']);
     for ($i = 0; $i < $count; $i++) {
         $rss['feed'][] = Format::forge($data['feedurl'][$i], 'xml')->to_array();
     }
     for ($i = 0; $i < count($rss['feed']); $i++) {
         if (isset($rss['feed'][$i]['channel']['item'])) {
             $data['company'] = $rss['feed'][$i]['channel']['title'];
             for ($y = 0; $y < 5; $y++) {
                 $data['title'][] = $rss['feed'][$i]['channel']['item'][$y]['title'];
                 $data['date'][] = date("Y年 n月 j日", strtotime($rss['feed'][$i]['channel']['item'][$y]['pubDate']));
                 $data['link'][] = $rss['feed'][$i]['channel']['item'][$y]['link'];
                 if (strstr($kaisya[$i], $data['company'])) {
                     $data['company_id'][] = $i;
                 }
             }
         } elseif (isset($rss['feed'][$i]['entry'])) {
             $data['company'] = $rss['feed'][$i]['title'];
             for ($y = 0; $y < 5; $y++) {
                 $data['title'][] = $rss['feed'][$i]['entry'][$y]['title'];
                 $data['date'][] = date("Y年 n月 j日", strtotime($rss['feed'][$i]['entry'][$y]['published']));
                 $data['link'][] = $rss['feed'][$i]['entry'][$y]['id'];
                 if (strstr($kaisya[$i], $data['company'])) {
                     $data['company_id'][] = $i;
                 }
             }
         } else {
             $data['company'] = $rss['feed'][$i]['channel']['title'];
             for ($y = 0; $y < 5; $y++) {
                 $data['title'][] = $rss['feed'][$i]['item'][$y]['title'];
                 $data['date'][] = date("Y年 n月 j日");
                 $data['link'][] = $rss['feed'][$i]['item'][$y]['link'];
                 if (strstr($kaisya[$i], $data['company'])) {
                     $data['company_id'][] = $i;
                 }
             }
         }
     }
     for ($i = 0; $i < count($data['title']); $i += 5) {
         for ($y = 0; $y < 5; $y++) {
             $dbdata = array('title' => $data['title'][$y + $i], 'company_id' => $data['company_id'][$i + $y], 'link' => $data['link'][$y + $i]);
             $dbdata['title'] = str_replace("'", "\\'", $dbdata['title']);
             $sql = "INSERT IGNORE INTO soccer (title,company_id,link) values('" . $dbdata['title'] . "','" . $dbdata['company_id'] . "','" . $dbdata['link'] . "')";
             $query = DB::query($sql);
             $result = $query->execute();
         }
     }
 }
Example #2
0
 public function run()
 {
     $FoursquareClient = new \Foursquare\Client();
     $file_content = File::read(DOCROOT . 'data/NY.csv', true);
     $data = Format::forge($file_content, 'csv')->to_array();
     $valid_counties = array();
     $valid_counties[] = 'BRONX';
     $valid_counties[] = 'QUEENS';
     $valid_counties[] = 'KINGS';
     $valid_counties[] = 'NEW YORK';
     $valid_counties[] = 'RICHMOND';
     $i = 0;
     $j = 0;
     foreach ($data as $key => $value) {
         if (!in_array($value['County'], $valid_counties)) {
             continue;
         }
         $i++;
         if ($i > 300) {
             break;
         }
         $match = $FoursquareClient->getVenueMapping($value['Latitude'], $value['Longitude'], $value['Store_Name']);
         if ($this->hasMatches($match, &$j)) {
             $this->logMatches($value, $match, $matches, $j, $i);
             continue;
         }
         $this->CliOutput('write', 'Stripping chars from Store_Name: ' . $value['Store_Name']);
         // remove numbers from store name
         $value['Store_Name'] = trim(preg_replace("/[0-9]/", "", $value['Store_Name']));
         $match = $FoursquareClient->getVenueMapping($value['Latitude'], $value['Longitude'], $value['Store_Name']);
         if ($this->hasMatches($match, &$j)) {
             $this->logMatches($value, $match, $matches, $j, $i);
             continue;
         }
         $this->CliOutput('error', 'No match for ' . $value['Store_Name'] . ' ' . $value['Address'] . ' ' . $value['City'] . ' ' . $value['Zip5']);
     }
     $this->CliOutput('write', 'Matches: ' . $j . '/' . $i);
 }
Example #3
0
 /**
  * @param $module string
  * @return mixed
  * @throws Exception
  */
 public function action_ajax($module)
 {
     $result = array('error' => false, 'message' => '');
     $params = Input::all();
     try {
         if (array_intersect_key(Input::get(), Input::post())) {
             throw new Exception('Get and post mustn\'t have the same keys');
         }
         $class_name = 'Model_' . $module;
         if (!class_exists($class_name) or $class_name::ajax() !== true) {
             return Response::forge(\View::forge('errors/404.twig', array('msg' => "That page couldn't be found!")), 404);
         }
         //TODO: check for crsf token
         $class = new $class_name();
         // NOTE: it is possible to process each kind of request by using
         // GET, POST, DELETE, PUT
         // But not all of the browsers supports this methods for using in forms
         $method = Input::get('method', 'GET');
         switch ($method) {
             case 'INSERT':
                 if (!($message = $class::validation($params))) {
                     $result['error'] = true;
                     $result['message'] = $class::get_message('insert_failed');
                 } else {
                     $class::insert($params);
                     $result['message'] = $class::get_message('insert_success');
                 }
                 break;
             case 'UPDATE':
                 $action = Input::get('action', 'update');
                 if (!method_exists($class, $action)) {
                     throw new Exception("Method {$action} doesn't exists");
                 }
                 $message = $class::$action($params);
                 $result['message'] = $class::get_message($message);
                 break;
             case 'DELETE':
                 $id = Input::get('id', false);
                 if (!$id) {
                     throw new Exception('On delete method \'id\' is required');
                 }
                 if (method_exists($class, 'delete')) {
                     $class::delete($id);
                     $result['message'] = $class::get_message('delete_message');
                 }
                 break;
             case 'GET':
                 $action = Input::get('action', false);
                 if (!$action) {
                     throw new Exception('For get method parameter \'action\' is required');
                 }
                 if (method_exists($class, $action)) {
                     $result['data'] = $class::$action($params);
                     $result['message'] = $class::get_message($action);
                 }
                 break;
         }
     } catch (Exception $e) {
         $result = array('error' => true, 'message' => $e->getMessage());
     }
     if (Input::is_ajax()) {
         $result = Format::forge()->to_json($result);
         return Response::forge($result);
     } else {
         if (isset($params['redirect_url'])) {
             Response::forge()->redirect($params['redirect_url']);
         } else {
             Response::forge()->redirect_back('/');
         }
     }
 }
Example #4
0
 public function manifest($files)
 {
     $shas = array();
     foreach ($files as $name => $path) {
         $shas[$name] = sha1(file_get_contents($path));
     }
     return \Fuel\Core\Format::forge($shas)->to_json();
 }
Example #5
0
 public static function setToYaml($dir, $data, $table)
 {
     $file = $dir . '/' . $table . '_fixt.yml';
     $data = Format::forge($data)->to_yaml();
     if (file_exists($file)) {
         rename($file, $file . '.old');
         echo 'Backed-up: ' . $file . PHP_EOL;
     }
     file_put_contents($file, $data);
     echo '  Created: ' . $file . PHP_EOL;
 }