feat/factory_creation (#1)
Prepping for launch. Reviewed-on: #1 Co-authored-by: Paul Couture <paul@paulcouture.com> Co-committed-by: Paul Couture <paul@paulcouture.com>
This commit was merged in pull request #1.
This commit is contained in:
60
site/database/seeders/EpisodeSeeder.php
Normal file
60
site/database/seeders/EpisodeSeeder.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Episode;
|
||||
use App\Models\Podcast;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Str;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class EpisodeSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$current_page = 1;
|
||||
$response = $this->getResponseFromApi($current_page);
|
||||
$last_page = $response->object()->last_page;
|
||||
$this->command->info('Last Page: ' . $last_page);
|
||||
$podcast = Podcast::find(1);
|
||||
while ($current_page <= $last_page) {
|
||||
$this->command->info('Getting Page ' . $current_page);
|
||||
foreach ($response->object()->data as $episode) {
|
||||
$podcastEpisode = Episode::where('title', $episode->title)->first();
|
||||
if (!$podcastEpisode) {
|
||||
$podcastEpisode = Episode::factory()->state([
|
||||
'podcast_id' => 1,
|
||||
'episode_date' => Carbon::parse($episode->show_date),
|
||||
'published' => (bool)$episode->published,
|
||||
'artwork_id' => null,
|
||||
'slug' => $episode->episode_number . '_' . Str::slug($episode->title),
|
||||
'title' => $episode->title,
|
||||
'mp3' => $episode->link,
|
||||
'created_at' => Carbon::parse($episode->created_at),
|
||||
'updated_at' => Carbon::parse($episode->updated_at),
|
||||
'legacy_id' => $episode->id ?? null
|
||||
])->create();
|
||||
} else {
|
||||
$podcastEpisode->legacy_id = $episode->id ?? null;
|
||||
if ($podcastEpisode->isDirty()) {
|
||||
$podcastEpisode->save();
|
||||
}
|
||||
}
|
||||
$this->command->info('Created ' . $episode->show_date . ' - (' . $episode->episode_number . ') ' . $episode->title);
|
||||
}
|
||||
$current_page++;
|
||||
$response = $this->getResponseFromApi($current_page);
|
||||
}
|
||||
}
|
||||
|
||||
private function getResponseFromApi($current_page) {
|
||||
$response = Http::timeout(180)
|
||||
->get('https://noagendaartgenerator.com/episodesjson?p=7476&page=' . $current_page);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
31
site/database/seeders/FixLegacyEpisodeSeeder.php
Normal file
31
site/database/seeders/FixLegacyEpisodeSeeder.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Episode;
|
||||
use App\Models\Podcast;
|
||||
use App\Models\Artwork;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facade\Log;
|
||||
|
||||
class FixLegacyEpisodeSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$episodes = Episode::all();
|
||||
foreach ($episodes as $episode) {
|
||||
if (is_null($episode->episode_number) || $episode->episode_number == 0) {
|
||||
$ep_num_arr = explode('_', $episode->slug);
|
||||
$episode->episode_number = $ep_num_arr[0];
|
||||
}
|
||||
if ($episode->isDirty()) {
|
||||
$episode->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
site/database/seeders/MapLegacyIdsSeeder.php
Normal file
17
site/database/seeders/MapLegacyIdsSeeder.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class MapLegacyIdsSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,31 @@ class PodcastSeeder extends Seeder
|
||||
$feed = 'https://hogstory.net/feed/podcast';
|
||||
$added = '2019-02-22 20:00:00';
|
||||
$this->createPodcast($name, $description, $website, $slug, $feed, $added);
|
||||
|
||||
|
||||
$name = 'Rare Encounter';
|
||||
$description = 'AbleKirby and coldacid converse on anime they watch, books and manga they read, games they play,
|
||||
and all the tech stuff that they come across.';
|
||||
$website = 'http://rareencounter.net';
|
||||
$slug = 'rare-encounter';
|
||||
$feed = 'https://rareencounter.net/external.php?name=RSS';
|
||||
$added = '2020-07-16 20:00:00';
|
||||
$this->createPodcast($name, $description, $website, $slug, $feed, $added);
|
||||
|
||||
$name = 'Unrelenting';
|
||||
$description = 'The Unrelenting Podcast is hosted by Gene Naftulvev and Darren O’Neill. It covers politics, technology, pop-culture, and more!';
|
||||
$website = 'http://unrelenting.show';
|
||||
$slug = 'unrelenting';
|
||||
$feed = 'https://www.unrelenting.show/feed/podcast/';
|
||||
$added = '2021-10-29 20:00:00';
|
||||
$this->createPodcast($name, $description, $website, $slug, $feed, $added);
|
||||
|
||||
$name = 'The Boostagram Ball';
|
||||
$description = 'The First Podcast with Value4Value Music hosted by Adam Curry';
|
||||
$website = 'https://boostagramball.com';
|
||||
$slug = 'boostagram-ball';
|
||||
$feed = 'https://mp3s.nashownotes.com/bballrss.xml';
|
||||
$added = '2023-07-29 20:00:00';
|
||||
$this->createPodcast($name, $description, $website, $slug, $feed, $added);
|
||||
}
|
||||
|
||||
private function createPodcast($name, $description, $website, $slug, $feed, $added) {
|
||||
|
||||
105
site/database/seeders/SeedFromOldApiSeeder.php
Normal file
105
site/database/seeders/SeedFromOldApiSeeder.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Models\Artist;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Episode;
|
||||
use App\Models\Podcast;
|
||||
use App\Models\Overlay;
|
||||
use App\Jobs\StashAndOptimizeLegacyArtworkJob;
|
||||
use App\Jobs\ImportLegacyUserJob;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class SeedFromOldApiSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//$this->populateLegacyArtworks();
|
||||
//die();
|
||||
$current_page = 0;
|
||||
$totalArtworks = 0;
|
||||
$missingArtworks = 0;
|
||||
$missingModel = 0;
|
||||
$response = $this->getResponseFromApi($current_page);
|
||||
$last_page = $response->object()->users->last_page;
|
||||
while ($current_page <= $last_page) {
|
||||
$this->command->info('Getting Page ' . $current_page);
|
||||
foreach ($response->object()->users->data as $user) {
|
||||
$this->command->line('Getting Art for ' . $user->profile->name . ', found ' . count($user->artworks) . ' artworks.');
|
||||
$totalArtworks += count($user->artworks);
|
||||
$legacyUser = Artist::where('name', $user->profile->name)->first();
|
||||
if (!$legacyUser) {
|
||||
ImportLegacyUserJob::dispatch($user);
|
||||
} else {
|
||||
if ($legacyUser->artworks->count() < count($user->artworks)) {
|
||||
$countDiff = count($user->artworks) - $legacyUser->artworks->count();
|
||||
$missingArtworks += $countDiff;
|
||||
$this->command->comment('Artist ID '
|
||||
. $legacyUser->id
|
||||
. ' '
|
||||
. $legacyUser->name
|
||||
. ' has '
|
||||
. $legacyUser->artworks->count()
|
||||
. ' artworks.');
|
||||
$this->command->error('Missing ' . $countDiff . ' artworks.');
|
||||
foreach ($user->artworks as $artwork) {
|
||||
$date = Carbon::parse($artwork->created_at);
|
||||
$basename = $date->format('Y')
|
||||
. '/' . $date->format('m')
|
||||
. '/' . Str::slug($legacyUser->name)
|
||||
. '-' . Str::slug($artwork->title)
|
||||
. '_' . $artwork->id . '.jpg';
|
||||
if (Storage::disk('static')->exists('artworks/' . $basename)) {
|
||||
$artworkModel = Artwork::where('filename', $basename)->first();
|
||||
if (!$artworkModel) {
|
||||
$missingModel++;
|
||||
$this->command->error($basename . ' exists.');
|
||||
StashAndOptimizeLegacyArtworkJob::dispatch($legacyUser, $artwork);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
$this->command->line('Locally stored all of ' . $legacyUser->name . '\'s artworks.');
|
||||
}
|
||||
}
|
||||
}
|
||||
$current_page++;
|
||||
$response = $this->getResponseFromApi($current_page);
|
||||
}
|
||||
$this->command->info('Total Artworks: ' . $totalArtworks);
|
||||
$this->command->info('Total Missing: ' . $missingArtworks);
|
||||
$this->command->info('Total Missing Model: ' . $missingModel);
|
||||
}
|
||||
|
||||
private function getResponseFromApi($current_page) {
|
||||
$response = Http::timeout(180)
|
||||
->get('https://noagendaartgenerator.com/artistapi',
|
||||
[
|
||||
'p' => '7476',
|
||||
'page' => $current_page,
|
||||
]
|
||||
);
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function populateLegacyArtworks() {
|
||||
$artworks = Artwork::whereNull('legacy_id')->get();
|
||||
foreach ($artworks as $artwork) {
|
||||
$file = pathinfo($artwork->filename);
|
||||
$filename = explode('_', $file['filename']);
|
||||
$legacy_id = end($filename);
|
||||
$artwork->legacy_id = $legacy_id;
|
||||
$artwork->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user