Anivisual.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 Anivisual extends Source {
  19. public $title = "Anivisual";
  20. protected $months = [
  21. 'Января' => 'January',
  22. 'Февраля' => 'February',
  23. 'Марта' => 'March',
  24. 'Апреля' => 'April',
  25. 'Мая' => 'May',
  26. 'Июня' => 'June',
  27. 'Июля' => 'July',
  28. 'Августа' => 'August',
  29. 'Сентября' => 'September',
  30. 'Октября' => 'October',
  31. 'Ноября' => 'November',
  32. 'Декабря' => 'December',
  33. ];
  34. protected function parse() {
  35. $text = $this->get_text('http://anivisual.net/stuff/1');
  36. try {
  37. $this->dom->loadStr($text, []);
  38. } catch (\Exception $e) {
  39. echo $e->getMessage();
  40. echo $e->getTraceAsString();
  41. return "";
  42. }
  43. unset($text);
  44. $games = $this->dom->find('.entryBlock');
  45. foreach ($games as $gameBlock) {
  46. $date = trim($gameBlock->find('.icon-calendar')->innerHtml);
  47. foreach ($this->months as $ruM => $enM) {
  48. $date = str_replace($ruM, $enM, $date);
  49. }
  50. $date = \DateTime::createFromFormat('d F Y', $date);
  51. $date = $date->format('U');
  52. if ($date < $this->period) continue;
  53. $game = new Game;
  54. $link = $gameBlock->find('.novel-ttl a')[0];
  55. $game->title = $link->innerHtml;
  56. $game->url = 'http://anivisual.net'.$link->getAttribute('href');
  57. $this->games[] = $game;
  58. }
  59. }
  60. }