/** * Execute the console command. * * @return mixed */ public function handle() { $this->scraper = new Scraper(); $this->postRepository = new PostRepository(new Post()); $this->info("Fetching posts from vdm..."); $posts = $this->scraper->scrap(200); $this->info(sprintf("Saving %d posts.", Arrays::size($posts))); Arrays::each($posts, function ($post) { $this->postRepository->create($post->toArray()); }); $this->info("Done."); }
public function testCanGetSizeOfArray() { $array = Arrays::size(array(1, 2, 3)); $this->assertEquals(3, $array); }
/** * Retrieves the last $postCount from vdm * * @param int $postCount : the number of entries to retrieve * @return mixed */ protected function getLatestPosts($postCount) { // posts array is empty $posts = []; // starting at page 0 (source achitecture) $pageId = 0; // fetching until enough posts are retrieved while (Arrays::size($posts) < $postCount) { $dom = HtmlDomParser::file_get_html(sprintf($this->getBaseUrl(), $pageId)); $domPosts = $dom->find('.article'); $posts = Arrays::merge($posts, $domPosts); $pageId++; } // sorting by descending date and keeping only the $postCount first entries return Arrays::from($posts)->sort('date', 'desc')->first($postCount)->obtain(); }
public function testCanGetcountArray() { $array = Arrays::size([1, 2, 3]); $this->assertEquals(3, $array); }
/** @test */ public function itRetrievesGoodAmountOfPosts() { $scraper = new Scraper(); $posts = $scraper->setBaseUrl(base_path() . "/tests/test.html")->scrap(10); $this->assertEquals(10, Arrays::size($posts)); }