DashingDon parser
This commit is contained in:
parent
1c7b852aaa
commit
afade9386d
|
@ -44,9 +44,9 @@ class Collect extends Command
|
|||
'Ifiction',
|
||||
'Gamejolt',
|
||||
'Textadventures',
|
||||
'Dashingdon',
|
||||
/*
|
||||
'vndb',
|
||||
'Dashingdon',
|
||||
*/
|
||||
];
|
||||
|
||||
|
|
|
@ -15,6 +15,6 @@ class Author extends Model
|
|||
}
|
||||
|
||||
public static function findByName($name) {
|
||||
return self::where('name', $name)->first();
|
||||
return self::whereRaw('LOWER(name) = ?', mb_strtolower($name))->first();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,4 +91,14 @@ class Game extends Model
|
|||
$out = implode("\n", $lines);
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function guessPlatform() {
|
||||
foreach($this->tags as $tag) {
|
||||
$platform = Platform::findByName($tag->title, false);
|
||||
if ($platform) {
|
||||
$this->platforms()->attach($platform);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ class Platform extends Model
|
|||
}
|
||||
|
||||
public static function findByName($name, $autocreate = true) {
|
||||
$model = self::where('title', $name)->first();
|
||||
$model = self::whereRaw('LOWER(title) = ?', mb_strtolower($name))->first();
|
||||
if (empty($model) && $autocreate) {
|
||||
$model = new self;
|
||||
$model->title = $name;
|
||||
|
|
|
@ -17,6 +17,8 @@ class Tag extends Model
|
|||
return $this->belongsToMany(Game::class, 'tags_games');
|
||||
}
|
||||
public static function findByName($name, $language) {
|
||||
return self::where('title', $name)->where('language_id', $language->id)->first();
|
||||
return self::whereRaw('LOWER(title) = ?', mb_strtolower($name))
|
||||
->where('language_id', $language->id)
|
||||
->first();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,10 @@
|
|||
*/
|
||||
namespace App\Sources;
|
||||
|
||||
use App\Models\Author;
|
||||
use \App\Models\Game;
|
||||
use App\Models\Language;
|
||||
use App\Models\Platform;
|
||||
use \App\Source;
|
||||
|
||||
/**
|
||||
|
@ -26,9 +29,31 @@ use \App\Source;
|
|||
*/
|
||||
class Dashingdon extends Source {
|
||||
public $title = "DashingDon";
|
||||
public $keyword = 'dashingdon';
|
||||
public function parse() {
|
||||
$text = $this->get_text("https://dashingdon.com/screenreader/");
|
||||
$platform = Platform::findByName('ChoiceScript');
|
||||
$language = Language::findByCode('en');
|
||||
$text = $this->get_text("https://dashingdon.com/");
|
||||
$this->loadStr($text);
|
||||
unset($text);
|
||||
$this->dom->filter('#allgames > article > fieldset > div > section.col.col-8')->each(function($gameBlock) use($platform, $language) {
|
||||
$game = new Game();
|
||||
$game->title = $gameBlock->filter('div.value-self > a')->text();
|
||||
$game = $this->findGame($game);
|
||||
$game->url = $gameBlock->filter('div.value-self > a')->attr('href');
|
||||
$game->url_play_online = $game->url;
|
||||
$game->description = trim($gameBlock->filter('.blurbbox')->text());
|
||||
$author_name = $gameBlock->filter('p > strong')->first()->text();
|
||||
$game->save();
|
||||
$game->languages()->attach($language);
|
||||
$game->platforms()->attach($platform);
|
||||
$author = Author::findByName($author_name);
|
||||
if (!$author) {
|
||||
$author = new Author();
|
||||
$author->name = $author_name;
|
||||
$author->save();
|
||||
}
|
||||
$game->authors()->attach($author);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,6 +97,7 @@ class Gamejolt extends Source {
|
|||
foreach ($tags as $t) {
|
||||
$game->tags()->attach($t);
|
||||
}
|
||||
$game->guessPlatform();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue