You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

80 lines
2.7 KiB

  1. #!/usr/bin/php
  2. <?php
  3. /*
  4. * Скрипт для того, чтобы заводить страницы русской IFWiki играм КРИЛа
  5. Copyright (C) 2017-2018 Alexander Yakovlev
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. use Symfony\Component\Yaml\Yaml;
  18. use \GuzzleHttp\Client as GuzzleClient;
  19. require "vendor/autoload.php";
  20. require "Game.php";
  21. require "Source.php";
  22. require "Wikipage.php";
  23. $config = Yaml::parse(file_get_contents('config.yml'));
  24. $pandoc = new Pandoc\Pandoc();
  25. $loader = new \Aura\Autoload\Loader;
  26. $loader->register();
  27. $loader->addPrefix('Source', 'Source');
  28. $client = new GuzzleClient([
  29. 'timeout' => 30,
  30. ]);
  31. $api = json_decode(file_get_contents('http://forum.ifiction.ru/extern.php?action=kril2018'));
  32. foreach ($api as $category) {
  33. $category_title = $category->category;
  34. $games = $category->games;
  35. foreach ($games as $game_data) {
  36. $game = new Game;
  37. $game->title = $game_data->full_title;
  38. $game->url_discussion = $game_data->url;
  39. $game->language = 'русский';
  40. $game->themes = [$game_data->rating];
  41. $game->description = $pandoc->runWith($game_data->description, [
  42. 'from' => 'html',
  43. 'to' => 'mediawiki'
  44. ]);
  45. if (isset($game_data->posters[0])) {
  46. $image_url = $game_data->posters[0];
  47. $response = $client->request('GET', $image_url, [
  48. 'sink' => 'tempfile.jpg',
  49. ]);
  50. $filename = $response->getHeaderLine('Content-Disposition');
  51. preg_match('/\.(\w+)";\ssize/', $filename, $matches);
  52. if (isset($matches[1])) {
  53. $game->image_extension = $matches[1];
  54. }
  55. $image = file_get_contents('tempfile.jpg');
  56. $game->image_data = $image;
  57. unlink('tempfile.jpg');
  58. }
  59. $game->date = new \DateTime('08.12.2018');
  60. $game->author = $game_data->authors;
  61. $game->platform = $game_data->platform;
  62. $files = $game_data->files;
  63. if (isset($files[0])) {
  64. $game->url_download = $files[0]->url;
  65. $game->url_download_description = $files[0]->title;
  66. }
  67. if (isset($files[1])) {
  68. $game->url_online = $files[1]->url;
  69. $game->url_online_description = $files[1]->title;
  70. }
  71. $page = new Wikipage($game);
  72. $page->create();
  73. }
  74. }