Skip to content

Commit

Permalink
feat: Adding lesson10 - load media item implementation by Yemi (#333)
Browse files Browse the repository at this point in the history
* feat: Adding homework10 - load media item implementation - Yemi

* feat: updated homework10 - removed all comments by Yemi

---------

Co-authored-by: Anthony D. Mays <[email protected]>
  • Loading branch information
jimoye244 and anthonydmays authored Oct 23, 2024
1 parent 903d387 commit 8d6467e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lesson_10/libraries/src/loaders/loaders.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { JamesCapparellLoader } from './james_capparell_loader.js';
import { JosephCaballeroLoader } from './joseph_caballero_loader.js';
import { KimberleeHaldaneLoader } from './kimberlee_haldane_loader.js';
import { NileJacksonLoader } from './nile_jackson_loader.js';
import { OyeyemiJimohLoader } from './oyeyemi_jimoh_loader.js';
import { PabloLimonParedesLoader } from './pablo_limon_paredes_loader.js';
import { ShawnDunsmoreLoader } from './shawn_dunsmore_loader.js';
import { TommyTranLoader } from './tommy_tran_loader.js';
Expand All @@ -20,7 +21,6 @@ import { ZionBuchananLoader } from './zion_buchanan_loader.js';

export const Loaders = Symbol.for('Loaders');

// Add your quiz provider here.
const LOADER_PROVIDERS = [
AmiyahJonesLoader,
AngelicaCastilloLoader,
Expand All @@ -33,6 +33,7 @@ const LOADER_PROVIDERS = [
JosephCaballeroLoader,
KimberleeHaldaneLoader,
NileJacksonLoader,
OyeyemiJimohLoader,
PabloLimonParedesLoader,
ShawnDunsmoreLoader,
TommyTranLoader,
Expand Down
45 changes: 45 additions & 0 deletions lesson_10/libraries/src/loaders/oyeyemi_jimoh_loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import csv from 'csv-parser';
import fs from 'fs';
import { Credit, MediaItem } from '../models/index.js';
import { Loader } from './loader.js';

export class OyeyemiJimohLoader implements Loader {
getLoaderName(): string {
return 'oyeyemijimoh';
}

async loadData(): Promise<MediaItem[]> {
const credits = await this.loadCredits();
const mediaItems = await this.loadMediaItems();

console.log(
`Loaded ${credits.length} credits and ${mediaItems.length} media items`,
);

return [...mediaItems.values()];
}

async loadMediaItems(): Promise<MediaItem[]> {
const mediaItems = [];
const readable = fs
.createReadStream('data/media_items.csv', 'utf-8')
.pipe(csv());
for await (const row of readable) {
const { id, type, title, year } = row;
mediaItems.push(new MediaItem(id, title, type, year, []));
}
return mediaItems;
}

async loadCredits(): Promise<Credit[]> {
const credits = [];
const readable = fs
.createReadStream('data/credits.csv', 'utf-8')
.pipe(csv());
for await (const row of readable) {
const { media_item_id, role, name } = row;
credits.push(new Credit(media_item_id, name, role));
}
return credits;
}
}

0 comments on commit 8d6467e

Please sign in to comment.