Exemple #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     Departure::truncate();
     Line::truncate();
     Stop::truncate();
     $cities = City::all();
     foreach ($cities as $city) {
         $this->info('importing city: ' . $city->name);
         $lines = Line::import($city);
         foreach ($lines as $line) {
             $this->info('importing line: ' . $line->name);
             $stops = Stop::fullImport($line);
         }
     }
 }
Exemple #2
0
 public static function import($url, $dir, $LineID, $CityID)
 {
     if (empty($stop_links)) {
         $stop_links = [];
     }
     if (!$url) {
         return [];
     }
     $stops = [];
     $client = new Client();
     $crawler = $client->request('GET', $url);
     $crawler->filter('a[target="R"]')->each(function ($link, $k) use(&$stops, &$stop_links, $dir, $LineID, $CityID) {
         $stop = self::getExistedOrNew(trim($link->text()), $CityID);
         $stop->deps = Departure::import($link->link()->getUri(), $dir, $stop->stopID, $LineID, $CityID);
         $stops[] = $stop;
     });
     return $stops;
 }