Exemple #1
0
 /**
  * DBから指定された$keyテーブルのMapを取得します。
  * なお、一度ロードしたDBのデータはキャッシュします。
  *
  * @param string $tableName テーブル名
  */
 public function getMap($tableName)
 {
     if (isset($this->_cache[$tableName])) {
         $map = $this->_cache[$tableName];
     } else {
         $map = parent::getRepository($tableName)->getMap();
     }
     return $map;
 }
Exemple #2
0
 /**
  * クロール対象のWoeidを取得します
  *
  * @return array
  */
 public function getCrawl()
 {
     $rWoeid = parent::getRepository('woeid');
     try {
         $woeids = $rWoeid->getCrawl();
     } catch (\Exception $e) {
         $this->logger->warn('- クロール対象のWoeid取得 失敗');
         throw $e;
     }
     return $woeids;
 }
Exemple #3
0
 /**
  * 実行
  */
 public function run($woeid, $weight = 1)
 {
     $this->logger->info('--- START Crawler Trend ---');
     // Trend取得
     $this->logger->info('- START get Trend by twitter');
     try {
         $trends = $this->container->get('app_service.component_twitter_rest_api_accessor')->getTrendsPlace($woeid);
     } catch (\Exception $e) {
         $this->logger->warn('- Failed get Trend by twitter');
         throw $e;
     }
     $this->logger->info('-  END  get Trend by twitter');
     // 登録
     $this->logger->info('- START Regist Trend Data');
     // Repository取得
     $em = parent::getManager();
     $rTrend = parent::getRepository('trend');
     try {
         $em->beginTransaction();
         $now = new \DateTime();
         foreach ($trends as $_trend) {
             $trendEntity = $rTrend->getUnityTrend($_trend['name']);
             // 未登録
             if (is_null($trendEntity)) {
                 // 新しいレコード生成
                 $this->logger->info('新規レコード登録');
                 $trendEntity = new Trend();
                 $trendEntity->setContent($_trend['name']);
                 $trendEntity->setWoeid($woeid);
                 if (preg_match('/^#/', $trendEntity->getContent())) {
                     $trendEntity->setType(Trend::TYPE_HASHTAG);
                 } else {
                     $trendEntity->setType(Trend::TYPE_KEYWORD);
                 }
             }
             $trendEntity->incrementWeight($weight);
             $trendEntity->setVolume($_trend['tweet_volume']);
             $trendEntity->setFound($now);
             // 登録
             $this->logger->info('登録(' . $trendEntity->getContent() . ')');
             $em->save($trendEntity);
             $em->manyFlush();
         }
         $em->commit();
     } catch (\Exception $e) {
         $this->logger->warn('- FAILED Regist Trend Data');
         $em->rollback();
         throw $e;
     }
     $this->logger->info('-  END  Regist Trend Data');
     $this->logger->info('---  END  Crawler Trend ---');
 }
Exemple #4
0
 /**
  * 指定された期間、WoeIdのトレンドを取得します
  *
  * @param int $woeid
  * @return array
  */
 public function getByPeriod($from = NULL, $to = NULL)
 {
     // DBからデータ取得
     $rTrend = parent::getRepository('trend');
     try {
         $trends = $rTrend->findAll();
         $sum = array();
         foreach ($trends as $_trend) {
             $sum[$_trend->getWoeid()][] = $_trend;
         }
     } catch (\Exception $e) {
         $this->logger->warn('- トレンド取得 失敗');
         throw $e;
     }
     return $sum;
 }
Exemple #5
0
 /**
  * WoeidをTwitterから取得して登録します
  */
 public function loadWoeid()
 {
     // Woeid取得
     try {
         $woeids = $this->container->get('app_service.component_twitter_rest_api_accessor')->getTrendsAvailable();
     } catch (\Exception $e) {
         $this->logger->warn('- Failed get Woeid by twitter');
         throw $e;
     }
     // 登録
     $em = parent::getManager();
     $rWoeid = parent::getRepository('woeid');
     try {
         $em->beginTransaction();
         foreach ($woeids as $_woeid) {
             $woeidEntity = $rWoeid->findOneByWoeid($_woeid['woeid']);
             if (is_null($woeidEntity)) {
                 $woeidEntity = new Woeid();
                 $woeidEntity->setWoeid($_woeid['woeid']);
                 $woeidEntity->setName($_woeid['name']);
             } else {
                 // 名前が変わってないかチェック
                 if ($woeidEntity->getName() !== $_woeid['name']) {
                     $woeidEntity->setName($_woeid['name']);
                 }
             }
             // 登録
             $this->logger->info(sprintf('登録(%s)', $woeidEntity->getWoeid()));
             $em->save($woeidEntity);
             $em->manyFlush();
         }
         $em->commit();
     } catch (\Exception $e) {
         $this->logger->warn('- FAILED Regist Woeid Data');
         $em->rollback();
         throw $e;
     }
 }