Archived
1
0
Fork 0

DashingDon parser

This commit is contained in:
Alexander Yakovlev 2020-10-21 13:45:37 +07:00
parent 1c7b852aaa
commit afade9386d
Signed by: oreolek
GPG key ID: 1CDC4B7820C93BD3
7 changed files with 43 additions and 5 deletions

View file

@ -44,9 +44,9 @@ class Collect extends Command
'Ifiction',
'Gamejolt',
'Textadventures',
'Dashingdon',
/*
'vndb',
'Dashingdon',
*/
];

View file

@ -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();
}
}

View file

@ -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;
}
}
}
}

View file

@ -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;

View file

@ -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();
}
}

View file

@ -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);
});
}
}

View file

@ -97,6 +97,7 @@ class Gamejolt extends Source {
foreach ($tags as $t) {
$game->tags()->attach($t);
}
$game->guessPlatform();
}
}
}