Archived
1
0
Fork 0

Resolved #7: Itch.io parser

This commit is contained in:
Alexander Yakovlev 2017-02-16 12:33:46 +07:00
parent 8180cab66a
commit 5162a072e7
3 changed files with 39 additions and 1 deletions

View file

@ -1,4 +1,6 @@
# Interactive Fiction news parser
Originally a parser for Russian Interactive Fiction, now it supports English games too.
Its function is simple
Its function is simple: it scans some game hosting sites, finds the new games (published in the last week) and prints a neat list in Markdown format. All automatic.
The `parser.php` is Russian sites, `english.php` is English sites.

35
Source_en/Itch.php Normal file
View file

@ -0,0 +1,35 @@
<?php
namespace Source;
use \Game;
class Itch extends Source {
public $title = "Itch.io";
protected function parse() {
$service = new \Sabre\Xml\Service();
$xml = file_get_contents("https://itch.io/games/newest/tag-text-based.xml");
$service->elementMap = [
'{}item' => function(\Sabre\Xml\Reader $reader) {
$game = new Game;
$keyValue = \Sabre\Xml\Deserializer\keyValue($reader, '{}item');
if (isset($keyValue['{}plainTitle'])) {
$game->title = $keyValue['{}plainTitle'];
}
if (isset($keyValue['{}link'])) {
$game->url = $keyValue['{}link'];
}
if (isset($keyValue['{}description'])) {
$game->description = $keyValue['{}description'];
}
if (isset($keyValue['{}pubDate'])) {
$game->date = strtotime($keyValue['{}pubDate']);
}
if ($game->date >= $this->period) {
$this->output .= $game->print();
}
return $game;
},
];
$dom = $service->parse($xml);
}
}

View file

@ -15,3 +15,4 @@ $loader->register();
$loader->addPrefix('Source', 'Source_en');
(new Source\Dashingdon())->print();
(new Source\Itch())->print();