Разбил по функциям
This commit is contained in:
parent
efeeb0aa70
commit
c4b74a4142
100
parser.php
100
parser.php
|
@ -1,63 +1,81 @@
|
|||
<?php
|
||||
require "vendor/autoload.php";
|
||||
require "game.php";
|
||||
use PHPHtmlParser\Dom;
|
||||
|
||||
$dom = new Dom;
|
||||
$period = strtotime("1 week ago");
|
||||
$formatter = new IntlDateFormatter( 'ru', IntlDateFormatter::LONG, IntlDateFormatter::NONE );
|
||||
|
||||
function printGame($url, $title, $author, $description = '') {
|
||||
echo "<li><a href='$url'>«".$title."»</a> — $author";
|
||||
if ($description) {
|
||||
echo "<br>$description";
|
||||
}
|
||||
echo "</li>\n";
|
||||
function startSection($name) {
|
||||
echo "<h4> $name </h4>\n<ul>\n";
|
||||
}
|
||||
function endSection() {
|
||||
echo "</ul>\n";
|
||||
}
|
||||
|
||||
echo "<h4> Apero </h4>\n";
|
||||
$dom->loadFromUrl('http://apero.ru/');
|
||||
$games = $dom->find('.tabled-game-block');
|
||||
foreach ($games as $game) {
|
||||
$date = trim($game->find('.game-updated-block')->innerHtml, "() \t\n\r\0\x0B");
|
||||
$date = $formatter->parse($date);
|
||||
if ($date < $period) continue;
|
||||
$author = trim($game->find('.game-author-block')[0]->find('a')->innerHtml);
|
||||
$title = trim($game->find('h2')[0]->find('a')[0]->innerHtml);
|
||||
$url = trim($game->find('h2')[0]->find('a')[0]->getAttribute('href'));
|
||||
$description = trim($game->find('.game-desc-block')[0]->innerHtml);
|
||||
printGame($url, $title, $author, $description);
|
||||
function apero() {
|
||||
global $dom, $period, $formatter;
|
||||
startSection("Apero");
|
||||
$dom->loadFromUrl('http://apero.ru/');
|
||||
$games = $dom->find('.tabled-game-block');
|
||||
foreach ($games as $gameBlock) {
|
||||
$date = trim($gameBlock->find('.game-updated-block')->innerHtml, "() \t\n\r\0\x0B");
|
||||
$date = $formatter->parse($date);
|
||||
if ($date < $period) continue;
|
||||
$game = new Game;
|
||||
$game->author = trim($gameBlock->find('.game-author-block')[0]->find('a')->innerHtml);
|
||||
$game->title = trim($gameBlock->find('h2')[0]->find('a')[0]->innerHtml);
|
||||
$game->url = trim($gameBlock->find('h2')[0]->find('a')[0]->getAttribute('href'));
|
||||
$game->description = trim($gameBlock->find('.game-desc-block')[0]->innerHtml);
|
||||
$game->print();
|
||||
}
|
||||
endSection();
|
||||
}
|
||||
|
||||
function insteadfeed($url) {
|
||||
global $dom, $period, $formatter;
|
||||
$dom->loadFromUrl($url);
|
||||
$games = $dom->find('.game');
|
||||
foreach ($games as $game) {
|
||||
$date = trim($game->find('.b .date b')->innerHtml);
|
||||
foreach ($games as $gameBlock) {
|
||||
$date = trim($gameBlock->find('.b .date b')->innerHtml);
|
||||
$date = DateTime::createFromFormat('Y.m.d', $date);
|
||||
$date = $date->format('U');
|
||||
if ($date < $period) continue;
|
||||
$author = str_replace(trim($game->find('span.author')->innerHtml), 'Автор: ', '');
|
||||
$title = trim($game->find('h2')[0]->find('a')[0]->innerHtml);
|
||||
$url = trim($game->find('h2')[0]->find('a')[0]->getAttribute('href'));
|
||||
$description = "";
|
||||
printGame($url, $title, $author, $description);
|
||||
$game = new Game;
|
||||
$game->author = str_replace(trim($gameBlock->find('span.author')->innerHtml), 'Автор: ', '');
|
||||
$game->title = trim($gameBlock->find('h2')[0]->find('a')[0]->innerHtml);
|
||||
$game->url = 'http://instead-games.ru/'.trim($gameBlock->find('h2')[0]->find('a')[0]->getAttribute('href'));
|
||||
$game->print();
|
||||
}
|
||||
}
|
||||
echo "<h4> Неофициальный INSTEAD репозиторий </h4>\n";
|
||||
insteadfeed("http://instead-games.ru/");
|
||||
echo "<h5> Песочница </h5>\n";
|
||||
insteadfeed("http://instead-games.ru/index.php?approved=0");
|
||||
|
||||
echo "<h4> Storymaze </h4>\n";
|
||||
$api = file_get_contents('http://storymaze.ru/api/stories/search?count=10&offset=0&asc=');
|
||||
$api = json_decode($api, TRUE);
|
||||
foreach ($api as $game) {
|
||||
$date = strtotime($game['publishStart']);
|
||||
if ($date < $period) continue;
|
||||
$title = $game['name'];
|
||||
$url = "http://storymaze.ru/story/view/".$game['id'].".html";
|
||||
$description = $game['description'];
|
||||
$author = $game['authorName'];
|
||||
printGame($url, $title, $author, $description);
|
||||
function instead() {
|
||||
startSection("Неофициальный INSTEAD репозиторий");
|
||||
insteadfeed("http://instead-games.ru/");
|
||||
endSection();
|
||||
echo "<h5> Песочница </h5>\n<ul>";
|
||||
insteadfeed("http://instead-games.ru/index.php?approved=0");
|
||||
endSection();
|
||||
}
|
||||
|
||||
function storymaze() {
|
||||
global $dom, $period, $formatter;
|
||||
startSection("Storymaze");
|
||||
$api = file_get_contents('http://storymaze.ru/api/stories/search?count=10&offset=0&asc=');
|
||||
$api = json_decode($api, TRUE);
|
||||
foreach ($api as $gameData) {
|
||||
$date = strtotime($gameData['publishStart']);
|
||||
if ($date < $period) continue;
|
||||
$game = new Game;
|
||||
$game->title = $gameData['name'];
|
||||
$game->url = "http://storymaze.ru/story/view/".$gameData['id'].".html";
|
||||
$game->description = $gameData['description'];
|
||||
$game->author = $gameData['authorName'];
|
||||
$game->print();
|
||||
}
|
||||
endSection();
|
||||
}
|
||||
|
||||
apero();
|
||||
instead();
|
||||
storymaze();
|
||||
|
|
Reference in a new issue