Archived
1
0
Fork 0

Anivisual UPD

This commit is contained in:
Alexander Yakovlev 2018-03-25 02:01:30 +07:00
parent 8a478a9d15
commit 39f3cee99a
3 changed files with 24 additions and 24 deletions

View file

@ -5,6 +5,11 @@ class Game {
public $title;
public $author;
public $description;
/**
* Дата выхода игры.
*
* @var DateTime
*/
public $date;
public $image;
public $platform;

View file

@ -21,17 +21,11 @@ class Anivisual extends Source {
];
protected function parse() {
$text = $this->get_text('http://anivisual.net/stuff/1');
try {
$this->dom->loadStr($text, []);
} catch (\Exception $e) {
echo $e->getMessage();
echo $e->getTraceAsString();
return "";
}
$this->loadStr($text);
unset($text);
$games = $this->dom->find('.entryBlock');
$games = $this->dom->filter('.entryBlock');
foreach ($games as $gameBlock) {
$date = trim($gameBlock->find('.icon-calendar')->innerHtml);
$date = trim($gameBlock->filter('.icon-calendar')->text());
foreach ($this->months as $ruM => $enM) {
$date = str_replace($ruM, $enM, $date);
}
@ -39,10 +33,10 @@ class Anivisual extends Source {
$date = $date->format('U');
if ($date < $this->period) continue;
$game = new Game;
$link = $gameBlock->find('.novel-ttl a')[0];
$link = $gameBlock->filter('.novel-ttl a')->first();
$game->title = htmlspecialchars_decode($link->innerHtml);
$game->url = 'http://anivisual.net'.$link->getAttribute('href');
$game->description = $gameBlock->find('span')->first()->text;
$game->description = $gameBlock->filter('span')->first()->text();
$games[] = $game;
@ -55,7 +49,7 @@ class Anivisual extends Source {
public function page($url) {
$text = $this->get_text($url);
try {
$this->dom->loadStr($text, []);
$this->loadStr($text);
} catch (\Exception $e) {
echo $e->getMessage();
echo $e->getTraceAsString();
@ -64,19 +58,17 @@ class Anivisual extends Source {
unset($text);
$game = new Game;
$game->url = $url;
$gameBlock = $this->dom->find('#casing-box');
try {
$date = trim($gameBlock->find('.icon-calendar')->first()->text);
$gameBlock = $this->dom->filter('#casing-box');
$date = trim($gameBlock->filter('.icon-calendar')->first()->text());
if (!empty($date)) {
foreach ($this->months as $ruM => $enM) {
$date = str_replace($ruM, $enM, $date);
}
$date = \DateTime::createFromFormat('d F Y', $date);
$date = $date->format('U');
$game->date = $date;
$game->date = \DateTime::createFromFormat('d F Y', $date);
unset($date);
} catch (\Exception $e) {}
$game->title = htmlspecialchars_decode($gameBlock->find('h1.logo')->text);
// $game->description = $this->dom->find('#content > section > span')->text;
}
$game->title = htmlspecialchars_decode($gameBlock->filter('h1.logo')->text());
$game->description = $this->dom->filter('#content > section > span')->text();
return $game;
}
}

View file

@ -87,7 +87,10 @@ class Wikipage {
} else {
$this->txtadd('author', ' |автор=[[Автор::'.$this->game->author.']]');
}
$this->txtadd('date', ' |вышла='.$this->game->date);
if (!empty($this->game->date)) {
$date =$this->game->date->format('d.m.Y');
$this->content .= PHP_EOL.' |вышла='.$date;
}
$this->txtadd('platform', ' |платформа='.$this->game->platform);
$this->txtadd('image', ' |обложка='.basename($this->game->image));
@ -110,7 +113,7 @@ class Wikipage {
protected function txtadd($param, $text) {
if (!empty($this->game->$param)) {
$this->content .= PHP_EOL.trim($text);
$this->content .= PHP_EOL.rtrim($text);
}
}
@ -121,7 +124,7 @@ class Wikipage {
* @return boolean
*/
protected function exists($pagename) {
$page = $this->services->newPageGetter()->getFromTitle($pagename);
$page = $this->services->newPageGetter()->getFromTitle((string) $pagename);
return !($page->getId() === 0);
}
}