Archived
1
0
Fork 0

WIP on collection

This commit is contained in:
Alexander Yakovlev 2019-09-13 12:56:52 +07:00
parent d6afa0e6fa
commit 997dd373f5
Signed by: oreolek
GPG key ID: 1CDC4B7820C93BD3
7 changed files with 199 additions and 172 deletions

View file

@ -28,8 +28,9 @@ class Collect extends Command
* @var array * @var array
*/ */
protected $parsers = [ protected $parsers = [
'Urq', //'Urq',
'Anivisual', 'Anivisual',
/*
'Kvester', 'Kvester',
//'vndb', //'vndb',
'Apero', 'Apero',
@ -44,6 +45,7 @@ class Collect extends Command
'Itch', 'Itch',
'Gamejolt', 'Gamejolt',
'Steam', 'Steam',
*/
]; ];
/** /**
@ -56,7 +58,11 @@ class Collect extends Command
foreach ($this->parsers as $parser) { foreach ($this->parsers as $parser) {
$cname = 'App\\Sources\\'.$parser; $cname = 'App\\Sources\\'.$parser;
try { try {
(new $cname())->parse(); $parser = new $cname();
$games = $parser->parse();
foreach ($games as $game) {
$parser->saveGame($game);
}
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error($e->getMessage()); Log::error($e->getMessage());
Log::debug($e->getTraceAsString()); Log::debug($e->getTraceAsString());

View file

@ -90,7 +90,29 @@ abstract class Source {
/** /**
* Save the game if not a duplicate. * Save the game if not a duplicate.
*/ */
protected function saveGame(Game $game) { public function saveGame(Game $game) {
$game->source = self::class;
$dbmodel = NULL;
if (isset($game->source_id)) {
$dbmodel = Game::where('source', $game->source)
->where('source_id', $game->source_id)
->first();
}
if ($dbmodel) {
$dbmodel->fill($game);
$dbmodel->save();
} else {
$game->save(); $game->save();
} }
}
/**
* Get the date of the last scraped game for this source.
*/
protected function getLastDate() {
Game::where('source', self::class)
->orderBy('created_at', 'desc')
->limit(1)
->value('created_at');
}
} }

View file

@ -41,23 +41,25 @@ class Anivisual extends Source {
$text = $this->get_text('http://anivisual.net/stuff/1'); $text = $this->get_text('http://anivisual.net/stuff/1');
$this->loadStr($text); $this->loadStr($text);
unset($text); unset($text);
$this->dom->filter('.entryBlock')->each(function($gameBlock) { $lastDate = $this->getLastDate();
$games = [];
$this->dom->filter('.entryBlock')->each(function($gameBlock) use($lastDate, &$games) {
$date = trim($gameBlock->filter('.icon-calendar')->text()); $date = trim($gameBlock->filter('.icon-calendar')->text());
foreach ($this->months as $ruM => $enM) { foreach ($this->months as $ruM => $enM) {
$date = str_replace($ruM, $enM, $date); $date = str_replace($ruM, $enM, $date);
} }
$date = \DateTime::createFromFormat('d F Y', $date); $date = \DateTime::createFromFormat('d F Y', $date);
if ($date >= $lastDate) {
return;
}
$game->date = $date; $game->date = $date;
$link = $gameBlock->filter('.novel-ttl a')->first(); $link = $gameBlock->filter('.novel-ttl a')->first();
$link = 'http://anivisual.net'.$link->attr('href'); $link = 'http://anivisual.net'.$link->attr('href');
$game = $this->page($link); $game = $this->page($link);
//$game = new Game;
//$game->title = htmlspecialchars_decode($link->html());
//$game->url = 'http://anivisual.net'.$link->attr('href');
//$game->description = $gameBlock->filter('span')->first()->text();
$this->saveGame($game); $games[] = $game;
}); });
return $games;
} }
public function checkPage($url) { public function checkPage($url) {

View file

@ -32,6 +32,7 @@ class Urq extends Source {
$game->author = trim($gameBlock->filter('.views-field-taxonomy-vocabulary-2')->first()->text()); $game->author = trim($gameBlock->filter('.views-field-taxonomy-vocabulary-2')->first()->text());
$game->title = trim($gameBlock->filter('.views-field-title')->text()); $game->title = trim($gameBlock->filter('.views-field-title')->text());
$game->url = 'http://urq.plut.info'.trim($gameBlock->filter('.views-field-title a')->attr('href')); $game->url = 'http://urq.plut.info'.trim($gameBlock->filter('.views-field-title a')->attr('href'));
$game->source_id = (int) str_replace('http://urq.plut.info/node/', '', $game->url);
$this->saveGame($game); $this->saveGame($game);
}); });
} }

View file

@ -1,7 +1,6 @@
<?php <?php
return [ return [
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Application Name | Application Name
@ -39,7 +38,7 @@ return [
| |
*/ */
'production' => false, 'production' => env('DEBUG'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -55,5 +54,4 @@ return [
'providers' => [ 'providers' => [
App\Providers\AppServiceProvider::class, App\Providers\AppServiceProvider::class,
], ],
]; ];

View file

@ -76,5 +76,4 @@ return [
'remove' => [ 'remove' => [
// .. // ..
], ],
]; ];

View file

@ -1,7 +1,6 @@
<?php <?php
return [ return [
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Default Database Connection Name | Default Database Connection Name