Resolved #7: Itch.io parser
This commit is contained in:
parent
8180cab66a
commit
5162a072e7
|
@ -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
35
Source_en/Itch.php
Normal 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);
|
||||
}
|
||||
}
|
|
@ -15,3 +15,4 @@ $loader->register();
|
|||
$loader->addPrefix('Source', 'Source_en');
|
||||
|
||||
(new Source\Dashingdon())->print();
|
||||
(new Source\Itch())->print();
|
||||
|
|
Reference in a new issue