From 0bfaac9118332f5fec341af8bac0335195a29ba4 Mon Sep 17 00:00:00 2001 From: Alain Van Driessche Date: Tue, 10 Oct 2023 15:24:24 +0200 Subject: [PATCH 1/2] baden --- app/Console/Commands/api/Baden.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/api/Baden.php b/app/Console/Commands/api/Baden.php index 5d18268ba..e7bc788fc 100644 --- a/app/Console/Commands/api/Baden.php +++ b/app/Console/Commands/api/Baden.php @@ -16,6 +16,7 @@ class Baden extends Command { use GermanTraits; + /** * The name and signature of the console command. * @@ -55,14 +56,30 @@ public function handle() $city = 'Baden'; + $client = new \GuzzleHttp\Client(); + + $url = "https://bw.codeweek.de/?tx_codeweekevents_api[action]=listForEu&tx_codeweekevents_api[controller]=Api&tx_codeweekevents_api[format]=.json&tx_typoscriptrendering[context]={%22record%22%3A%22pages_1%22%2C%22path%22%3A%22tt_content.list.20.codeweekevents_api%22}&cHash=74bb9d71d62e381ebe95b33c1e197943"; dump("Loading $city events"); - $response = Http::get($url); + $guzzle = $client->request('get', $url); + + dd($guzzle->getBody()->getContents()); + + $url = json_decode(json_encode($url, JSON_FORCE_OBJECT)); + + $response = Http::withOptions(['debug' => true])-> +// withUrlParameters([ +// 'endpoint' => 'https://bw.codeweek.de', +// 'test' => '?tx_codeweekevents_api[action]=listForEu&tx_codeweekevents_api[controller]=Api&tx_codeweekevents_api[format]=.json&tx_typoscriptrendering[context]={"record":"pages_1","path":"tt_content.list.20.codeweekevents_api"}&cHash=74bb9d71d62e381ebe95b33c1e197943' +// ])-> + get($url); $json = $response->json(); - if (is_null($json)){ + dd($json); + + if (is_null($json)) { Log::info("!!! No data in feed from $city API:"); return 0; } @@ -70,12 +87,9 @@ public function handle() $this->createRSSItem($json, $city); - return Artisan::call("import:baden"); - - } public function getCustomTag($item, $tag) From baf7a3ad1917057941f6992605d45dff843a5311 Mon Sep 17 00:00:00 2001 From: Alain Van Driessche Date: Tue, 10 Oct 2023 17:14:01 +0200 Subject: [PATCH 2/2] German using guzzle --- app/Console/Commands/api/Baden.php | 21 +-------------------- app/Console/Commands/api/Bayern.php | 6 ++---- app/Console/Commands/api/Berlin.php | 6 ++---- app/Console/Commands/api/Bonn.php | 6 ++---- app/Console/Commands/api/Bremen.php | 6 ++---- app/Console/Commands/api/Dresden.php | 6 ++---- app/Console/Commands/api/GermanTraits.php | 10 ++++++++-- app/Console/Commands/api/Hamburg.php | 6 ++---- app/Console/Commands/api/Leipzig.php | 6 ++---- app/Console/Commands/api/Muensterland.php | 6 +++--- app/Console/Commands/api/Nordhessen.php | 6 ++---- app/Console/Commands/api/Thueringen.php | 6 ++---- app/Helpers/ImporterHelper.php | 3 ++- 13 files changed, 32 insertions(+), 62 deletions(-) diff --git a/app/Console/Commands/api/Baden.php b/app/Console/Commands/api/Baden.php index e7bc788fc..3b51df7a3 100644 --- a/app/Console/Commands/api/Baden.php +++ b/app/Console/Commands/api/Baden.php @@ -56,28 +56,10 @@ public function handle() $city = 'Baden'; - $client = new \GuzzleHttp\Client(); - - $url = "https://bw.codeweek.de/?tx_codeweekevents_api[action]=listForEu&tx_codeweekevents_api[controller]=Api&tx_codeweekevents_api[format]=.json&tx_typoscriptrendering[context]={%22record%22%3A%22pages_1%22%2C%22path%22%3A%22tt_content.list.20.codeweekevents_api%22}&cHash=74bb9d71d62e381ebe95b33c1e197943"; dump("Loading $city events"); - $guzzle = $client->request('get', $url); - - dd($guzzle->getBody()->getContents()); - - $url = json_decode(json_encode($url, JSON_FORCE_OBJECT)); - - $response = Http::withOptions(['debug' => true])-> -// withUrlParameters([ -// 'endpoint' => 'https://bw.codeweek.de', -// 'test' => '?tx_codeweekevents_api[action]=listForEu&tx_codeweekevents_api[controller]=Api&tx_codeweekevents_api[format]=.json&tx_typoscriptrendering[context]={"record":"pages_1","path":"tt_content.list.20.codeweekevents_api"}&cHash=74bb9d71d62e381ebe95b33c1e197943' -// ])-> - get($url); - - $json = $response->json(); - - dd($json); + $json = $this->loadJson($url); if (is_null($json)) { Log::info("!!! No data in feed from $city API:"); @@ -86,7 +68,6 @@ public function handle() $this->createRSSItem($json, $city); - return Artisan::call("import:baden"); diff --git a/app/Console/Commands/api/Bayern.php b/app/Console/Commands/api/Bayern.php index 68eb4a5dd..fc94cc511 100644 --- a/app/Console/Commands/api/Bayern.php +++ b/app/Console/Commands/api/Bayern.php @@ -62,11 +62,9 @@ public function handle() dump("Loading $city events"); $force = $this->option('force'); - $response = Http::get($url); + $json = $this->loadJson($url); - $json = $response->json(); - - if (is_null($json)){ + if (is_null($json)) { Log::info("!!! No data in feed from $city API:"); return 0; } diff --git a/app/Console/Commands/api/Berlin.php b/app/Console/Commands/api/Berlin.php index 542e165cd..0db868bb4 100644 --- a/app/Console/Commands/api/Berlin.php +++ b/app/Console/Commands/api/Berlin.php @@ -62,11 +62,9 @@ public function handle() dump("Loading $city events"); $force = $this->option('force'); - $response = Http::get($url); + $json = $this->loadJson($url); - $json = $response->json(); - - if (is_null($json)){ + if (is_null($json)) { Log::info("!!! No data in feed from $city API:"); return 0; } diff --git a/app/Console/Commands/api/Bonn.php b/app/Console/Commands/api/Bonn.php index a293f1610..eec1554ca 100644 --- a/app/Console/Commands/api/Bonn.php +++ b/app/Console/Commands/api/Bonn.php @@ -59,11 +59,9 @@ public function handle() $url = "https://bonn.codeweek.de/?tx_codeweekevents_api[action]=listForEu&tx_codeweekevents_api[controller]=Api&tx_codeweekevents_api[format]=.json&tx_typoscriptrendering[context]={%22record%22%3A%22pages_1%22%2C%22path%22%3A%22tt_content.list.20.codeweekevents_api%22}&cHash=74bb9d71d62e381ebe95b33c1e197943"; dump("Loading $city events"); - $response = Http::get($url); + $json = $this->loadJson($url); - $json = $response->json(); - - if (is_null($json)){ + if (is_null($json)) { Log::info("!!! No data in feed from $city API:"); return 0; } diff --git a/app/Console/Commands/api/Bremen.php b/app/Console/Commands/api/Bremen.php index d8ec875b8..383ccbd3e 100644 --- a/app/Console/Commands/api/Bremen.php +++ b/app/Console/Commands/api/Bremen.php @@ -58,11 +58,9 @@ public function handle() $url = "https://bremen.codeweek.de/?tx_codeweekevents_api[action]=listForEu&tx_codeweekevents_api[controller]=Api&tx_codeweekevents_api[format]=.json&tx_typoscriptrendering[context]={%22record%22%3A%22pages_1%22%2C%22path%22%3A%22tt_content.list.20.codeweekevents_api%22}&cHash=74bb9d71d62e381ebe95b33c1e197943"; dump("Loading $city events"); - $response = Http::get($url); + $json = $this->loadJson($url); - $json = $response->json(); - - if (is_null($json)){ + if (is_null($json)) { Log::info("!!! No data in feed from $city API:"); return 0; } diff --git a/app/Console/Commands/api/Dresden.php b/app/Console/Commands/api/Dresden.php index 36100c324..2dd39a529 100644 --- a/app/Console/Commands/api/Dresden.php +++ b/app/Console/Commands/api/Dresden.php @@ -58,11 +58,9 @@ public function handle() $url = "https://dresden.codeweek.de/?tx_codeweekevents_api[action]=listForEu&tx_codeweekevents_api[controller]=Api&tx_codeweekevents_api[format]=.json&tx_typoscriptrendering[context]={%22record%22%3A%22pages_1%22%2C%22path%22%3A%22tt_content.list.20.codeweekevents_api%22}&cHash=74bb9d71d62e381ebe95b33c1e197943"; dump("Loading $city events"); - $response = Http::get($url); + $json = $this->loadJson($url); - $json = $response->json(); - - if (is_null($json)){ + if (is_null($json)) { Log::info("!!! No data in feed from $city API:"); return 0; } diff --git a/app/Console/Commands/api/GermanTraits.php b/app/Console/Commands/api/GermanTraits.php index f8f6c4296..3cf6862c7 100644 --- a/app/Console/Commands/api/GermanTraits.php +++ b/app/Console/Commands/api/GermanTraits.php @@ -12,6 +12,13 @@ trait GermanTraits { + + private function loadJson($url){ + $client = new \GuzzleHttp\Client(); + $guzzle = $client->request('get', $url); + + return json_decode($guzzle->getBody(), true); + } /** * @param $json */ @@ -25,7 +32,6 @@ private function createRSSItem($json, $city): void $className = '\App\RSSItems\\' . $city . 'RSSItem'; $RSSitem = new $className; - $RSSitem->uid = $item['uid']; $RSSitem->title = $item['title']; $RSSitem->description = $item['description']; @@ -41,7 +47,7 @@ private function createRSSItem($json, $city): void $RSSitem->user_publicEmail = $item['user']['publicEmail']; $RSSitem->user_type = $item['user']['type']['identifier'] ?? ''; $RSSitem->user_website = $item['user']['www']; - $RSSitem->activity_type = $item['type']['identifier']; + $RSSitem->activity_type = $item['type']['identifier'] ?? 'invite-in-person'; $RSSitem->tags = trim(implode(";", Arr::pluck($item['tags'], 'title'))); $RSSitem->themes = trim(implode(",", Arr::pluck($item['themes'], 'identifier'))); $RSSitem->audience = trim(implode(",", Arr::pluck($item['audience'], 'identifier'))); diff --git a/app/Console/Commands/api/Hamburg.php b/app/Console/Commands/api/Hamburg.php index e2682866a..032f528bd 100644 --- a/app/Console/Commands/api/Hamburg.php +++ b/app/Console/Commands/api/Hamburg.php @@ -61,11 +61,9 @@ public function handle() dump("Loading $city events"); $force = $this->option('force'); - $response = Http::get($url); + $json = $this->loadJson($url); - $json = $response->json(); - - if (is_null($json)){ + if (is_null($json)) { Log::info("!!! No data in feed from $city API:"); return 0; } diff --git a/app/Console/Commands/api/Leipzig.php b/app/Console/Commands/api/Leipzig.php index 91a104433..41ebdfc26 100644 --- a/app/Console/Commands/api/Leipzig.php +++ b/app/Console/Commands/api/Leipzig.php @@ -63,11 +63,9 @@ public function handle() dump("Loading $city events"); $force = $this->option('force'); - $response = Http::get($url); + $json = $this->loadJson($url); - $json = $response->json(); - - if (is_null($json)){ + if (is_null($json)) { Log::info("!!! No data in feed from $city API:"); return 0; } diff --git a/app/Console/Commands/api/Muensterland.php b/app/Console/Commands/api/Muensterland.php index 5a585a439..94447624d 100644 --- a/app/Console/Commands/api/Muensterland.php +++ b/app/Console/Commands/api/Muensterland.php @@ -58,11 +58,11 @@ public function handle() $url = "https://muensterland.codeweek.de/?tx_codeweekevents_api[action]=listForEu&tx_codeweekevents_api[controller]=Api&tx_codeweekevents_api[format]=.json&tx_typoscriptrendering[context]={%22record%22%3A%22pages_1%22%2C%22path%22%3A%22tt_content.list.20.codeweekevents_api%22}&cHash=74bb9d71d62e381ebe95b33c1e197943"; dump("Loading $city events"); - $response = Http::get($url); + $json = $this->loadJson($url); - $json = $response->json(); - if (is_null($json)){ + + if (is_null($json)) { Log::info("!!! No data in feed from $city API:"); return 0; } diff --git a/app/Console/Commands/api/Nordhessen.php b/app/Console/Commands/api/Nordhessen.php index e11d5f20a..f1b728184 100644 --- a/app/Console/Commands/api/Nordhessen.php +++ b/app/Console/Commands/api/Nordhessen.php @@ -62,11 +62,9 @@ public function handle() dump("Loading $city events"); $force = $this->option('force'); - $response = Http::get($url); + $json = $this->loadJson($url); - $json = $response->json(); - - if (is_null($json)){ + if (is_null($json)) { Log::info("!!! No data in feed from $city API:"); return 0; } diff --git a/app/Console/Commands/api/Thueringen.php b/app/Console/Commands/api/Thueringen.php index c10fd0ccb..073ca4213 100644 --- a/app/Console/Commands/api/Thueringen.php +++ b/app/Console/Commands/api/Thueringen.php @@ -63,11 +63,9 @@ public function handle() dump("Loading $city events"); $force = $this->option('force'); - $response = Http::get($url); + $json = $this->loadJson($url); - $json = $response->json(); - - if (is_null($json)){ + if (is_null($json)) { Log::info("!!! No data in feed from $city API:"); return 0; } diff --git a/app/Helpers/ImporterHelper.php b/app/Helpers/ImporterHelper.php index be740d171..6b5d5aa1d 100644 --- a/app/Helpers/ImporterHelper.php +++ b/app/Helpers/ImporterHelper.php @@ -17,7 +17,8 @@ class ImporterHelper public static function getGermanCities() { - return ['hamburg', 'baden', 'bonn', 'berlin', 'leipzig', 'dresden', 'thueringen', 'bremen', 'muensterland', 'nordhessen', 'bayern']; +// return ['hamburg', 'baden', 'bonn', 'berlin', 'leipzig', 'dresden', 'thueringen', 'bremen', 'muensterland', 'nordhessen', 'bayern']; + return ['hamburg', 'baden', 'bonn', 'berlin', 'leipzig', 'thueringen', 'bremen', 'muensterland', 'nordhessen', 'bayern']; } //Create or load Technical user based on username