Exemplo n.º 1
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 ---');
 }
Exemplo n.º 2
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;
     }
 }