Laatste nieuws balk

This commit is contained in:
2020-01-18 12:12:15 +01:00
parent 811fab79d5
commit 8c182c9c94
4 changed files with 60 additions and 25 deletions

View File

@@ -2,11 +2,14 @@
namespace App\Console;
use Illuminate\Support\Facades\Storage;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
private $API_URL;
/**
* The Artisan commands provided by your application.
*
@@ -24,6 +27,20 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$this->API_URL = env('API_URL', 'http://api.6fm.nl/');
// Update latest news (3 items)
$schedule->call(function() {
$latest_news = json_decode(file_get_contents($this->API_URL . 'nieuws/overzicht?pagina=1&aantal=3'));
$news = [];
foreach($latest_news->news as $item_data)
{
$news[] = new \Model\NewsItem($item_data);
}
Storage::disk('local')->put('laatste_nieuws.json', json_encode($news));
})->everyMinute();
// $schedule->command('inspire')
// ->hourly();
}