/** * 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."); }
/** * Creates corresponding Post model for given DOM object * * @param $article : the DOM object * @return $post : Properly formated Post entity */ protected function persistPost($article) { $post = new Post(); $post->content = Scraper::parseContent($article); $post->date = Scraper::parseDate($article); $post->author = Scraper::parseAuthor($article); $post->vdm_id = Scraper::parseVdmId($article); return $post; }
/** @test */ public function itRetrievesGoodAmountOfPosts() { $scraper = new Scraper(); $posts = $scraper->setBaseUrl(base_path() . "/tests/test.html")->scrap(10); $this->assertEquals(10, Arrays::size($posts)); }