public function processPage(Crawler $crawler) { $crawler->filter(".forumline.tablesorter tr")->each(function (Crawler $node) { $filter = $node->filter("td"); if (count($filter) && count($filter->eq(3))) { $name = trim($filter->eq(3)->text()); $torrentLink = trim($filter->eq(3)->filter('a')->attr('href')); $torrentLink = str_replace("./", 'http://rustorka.com/forum/', $torrentLink); $id = substr($torrentLink, strpos($torrentLink, "=") + 1); $seeders = trim($filter->eq(7)->text()); $leechers = trim($filter->eq(8)->text()); $downloadTimes = trim($filter->eq(9)->text()); $torrent = Torrent::where('name', '=', $name)->first(); if (!$torrent) { $torrent = new Torrent(); } $torrent->name = $name; $torrent->torrentLink = $torrentLink; $torrent->id = (int) $id; $torrent->seeders = (int) $seeders; $torrent->leechers = (int) $leechers; $torrent->downloadTimes = (int) $downloadTimes; $torrent->isSent = false; $torrent->save(); } }); }
/** * Execute the console command. * * @return mixed */ public function handle() { $torrentsModels = Torrent::where('seeders', '>', 29)->where('isSent', '=', false); $torrents = $torrentsModels->get(); if (count($torrents)) { Mail::send('emails.freshTorrents', ['torrents' => $torrents], function (Message $m) { $m->from(env("MAIL_FROM_ADDRESS"), 'AxelPAL'); $m->to(env("EMAIL_TO_SEND"), "AxelPAL")->subject('Новые торренты за ' . date("Y-m-d")); }); $torrentsModels->update(['isSent' => true]); } }