Apero.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. Microblog bot for game release notifications
  4. Copyright (C) 2017 Alexander Yakovlev
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. namespace Source;
  17. use \Game;
  18. class Apero extends Source {
  19. public $title = "Apero";
  20. protected function parse() {
  21. $formatter = new \IntlDateFormatter( 'ru', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE );
  22. $text = $this->get_text('http://apero.ru/');
  23. $this->dom->loadStr($text, []);
  24. unset($text);
  25. $games = $this->dom->find('.tabled-game-block');
  26. foreach ($games as $gameBlock) {
  27. $date = trim($gameBlock->find('.game-updated-block')->innerHtml, "() \t\n\r\0\x0B");
  28. $date = $formatter->parse($date);
  29. if ($date < $this->period) continue;
  30. $game = new Game;
  31. $game->author = trim($gameBlock->find('.game-author-block')[0]->find('a')->innerHtml);
  32. $game->title = trim($gameBlock->find('h2')[0]->find('a')[0]->innerHtml);
  33. $game->url = trim($gameBlock->find('h2')[0]->find('a')[0]->getAttribute('href'));
  34. $game->description = trim($gameBlock->find('.game-desc-block')[0]->innerHtml);
  35. $this->games[] = $game;
  36. }
  37. }
  38. }