Archived
1
0
Fork 0
This repository has been archived on 2021-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
ifnews/app/Sources/Dashingdon.php

60 lines
2.1 KiB
PHP

<?php
/*
A set of utilities for tracking text-based game releases
Copyright (C) 2017-2018 Alexander Yakovlev
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace App\Sources;
use App\Models\Author;
use \App\Models\Game;
use App\Models\Language;
use App\Models\Platform;
use \App\Source;
/**
* And here's the problem: there are no publication dates.
*/
class Dashingdon extends Source {
public $title = "DashingDon";
public $keyword = 'dashingdon';
public function parse() {
$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()->sync([$language->id]);
$game->platforms()->sync([$platform->id]);
$author = Author::findByName($author_name);
if (!$author) {
$author = new Author();
$author->name = $author_name;
$author->save();
}
$game->authors()->sync([$author->id]);
});
}
}