get(); foreach ($sources as $source) { if ($synchronous) { ImportEventsJob::dispatchSync($source); } else { ImportEventsJob::dispatch($source); } } return count($sources); } /** * Importiere von einer spezifischen Quelle */ public function importFromSource(Source $source, $synchronous = false) { if ($synchronous) { ImportEventsJob::dispatchSync($source); } else { ImportEventsJob::dispatch($source); } } /** * Beispiel: API-Client für Stadt Dresden * * Hinweis: Dies müsste in der fetchExternalEvents-Methode * des ImportEventsJob verwendet werden. */ public function fetchFromDresdenCityAPI($limit = 1000) { $response = Http::withHeaders([ 'Accept' => 'application/json', ])->get('https://api.stadt-dresden.de/events', [ 'limit' => $limit, 'offset' => 0, ]); if ($response->failed()) { throw new \Exception("Dresden API request failed: " . $response->status()); } return $response->json('data'); } /** * Beispiel: Web-Scraping mit Symfony/DomCrawler * * Installiere: composer require symfony/dom-crawler symfony/http-client */ public function scrapeFromWebsite($url) { $client = new \Symfony\Component\HttpClient\HttpClient(); $response = $client->request('GET', $url); $html = $response->getContent(); // Verwende DomCrawler zum Parsen $crawler = new \Symfony\Component\DomCrawler\Crawler($html); $events = []; $crawler->filter('.event-item')->each(function ($node) use (&$events) { $events[] = [ 'title' => $node->filter('.event-title')->text(), 'description' => $node->filter('.event-description')->text(), 'location' => $node->filter('.event-location')->text(), 'date' => $node->filter('.event-date')->attr('data-date'), ]; }); return $events; } }