From 5162a072e7356b5ccf98bfeee0b6e723b9dbc8e4 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Thu, 16 Feb 2017 12:33:46 +0700 Subject: [PATCH] Resolved #7: Itch.io parser --- README.md | 4 +++- Source_en/Itch.php | 35 +++++++++++++++++++++++++++++++++++ english.php | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Source_en/Itch.php diff --git a/README.md b/README.md index 83715e7..034fe99 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/Source_en/Itch.php b/Source_en/Itch.php new file mode 100644 index 0000000..1971f66 --- /dev/null +++ b/Source_en/Itch.php @@ -0,0 +1,35 @@ +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); + } +} diff --git a/english.php b/english.php index 9050d49..3384a64 100644 --- a/english.php +++ b/english.php @@ -15,3 +15,4 @@ $loader->register(); $loader->addPrefix('Source', 'Source_en'); (new Source\Dashingdon())->print(); +(new Source\Itch())->print();