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.

70 lines
1.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php
  2. namespace App\Commands;
  3. use Illuminate\Console\Scheduling\Schedule;
  4. use LaravelZero\Framework\Commands\Command;
  5. use Illuminate\Support\Facades\Http;
  6. use App\Handlers\HandlerFactory;
  7. class CrawlerRunCommand extends Command
  8. {
  9. /**
  10. * The signature of the command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'crawler:run';
  15. /**
  16. * The description of the command.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Command description';
  21. /**
  22. * Execute the console command.
  23. *
  24. * @return mixed
  25. */
  26. public function handle()
  27. {
  28. $sources = [
  29. 'https://steadyhq.com/rss/krautreporter?auth=f7da00aa-fd3f-4411-a16f-138a1ce88dcc',
  30. 'https://steadyhq.com/rss/insertmoin?auth=d37bffc9-9a84-4eed-95f6-3b6cb77c2406'
  31. ];
  32. foreach ($sources as $source) {
  33. // getting handler class and create object
  34. $handlerClass = HandlerFactory::getResponseHandlerClass($source->response_handler_class);
  35. $handler = new $handlerClass($source);
  36. $response = $handler->getResponse();
  37. // if it is a 200
  38. if ($response->ok()) {
  39. $handler->run();
  40. // if there is an error on the source
  41. } else if ($response->serverError()) {
  42. }
  43. }
  44. }
  45. /**
  46. * Define the command's schedule.
  47. *
  48. * @param \Illuminate\Console\Scheduling\Schedule $schedule
  49. * @return void
  50. *
  51. */
  52. public function schedule(Schedule $schedule): void
  53. {
  54. $schedule->command(static::class)->everyMinute();
  55. }
  56. }