From cdc6b0b5966060a82d845c799730fdc2e10a4483 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Sun, 22 Jan 2017 12:00:56 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B0=D1=80=D1=81=D0=B5=D1=80=20=D0=93?= =?UTF-8?q?=D0=B8=D0=BF=D0=B5=D1=80=D0=BA=D0=BD=D0=B8=D0=B3=D0=B8,=20?= =?UTF-8?q?=D1=87=D0=B0=D1=81=D1=82=D0=B8=D1=87=D0=BD=D0=BE=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=87=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.php | 1 + hyperbook.php | 42 ++++++++++++++++++++++++++++++++++++++++++ parser.php | 4 +++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 hyperbook.php diff --git a/game.php b/game.php index 52a9dc4..eb0703f 100644 --- a/game.php +++ b/game.php @@ -4,6 +4,7 @@ class Game { public $title; public $author; public $description; + public $date; public function print() { echo "
  • «".$this->title."» — $this->author"; if ($this->description) { diff --git a/hyperbook.php b/hyperbook.php new file mode 100644 index 0000000..de1cec0 --- /dev/null +++ b/hyperbook.php @@ -0,0 +1,42 @@ +loadFromUrl('http://hyperbook.ru/lib.php?sort=time'); + $container = $dom->find('#listPubs'); + $games = []; + foreach ($container->find("h3") as $heading) { + $game = new Game; + $link = $heading->find('a')[0]; + $game->title = $link->innerHtml; + $game->url = $link->getAttribute('href'); + $games[] = $game; + } + $i = 0; + foreach ($container->find("div") as $author) { + if ($author->getAttribute('style') !== 'text-align:left;margin-bottom:4px;') { + continue; + } + $games[$i]->author = $author->innerHtml; + $i++; + } + $i = 0; + foreach ($container->find("div.small") as $small) { + if($small->getAttribute('style') === 'float: left; width: 20%; text-align:right;') { + $games[$i]->date = $small->innerHtml; + } + if($small->getAttribute('class') === FALSE) { + $games[$i]->description = $small->innerHtml; + $i++; + } + } + foreach ($games as $game) { + $date = DateTime::createFromFormat('d.m.y', $game->date); + if ($date === false) continue; + $date = $date->format('U'); + if ($date < $period) continue; + + $game->print(); + } + endSection(); +} diff --git a/parser.php b/parser.php index b786462..7168a54 100644 --- a/parser.php +++ b/parser.php @@ -2,6 +2,7 @@ require "vendor/autoload.php"; require "game.php"; require "apero.php"; +require "hyperbook.php"; require "instead.php"; require "storymaze.php"; use PHPHtmlParser\Dom; @@ -19,4 +20,5 @@ function endSection() { //apero(); //instead(); -storymaze(); +//storymaze(); +hyperbook();