-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Fixed two files for lesson 10 by Hummad Tanweer (#348)
* Feat: Fixed two files for lesson 10 by Hummad Tanweer * resloved conflicts * changes to loader file * Feat: Fixed two files for lesson 10 by Hummad Tanweer * resloved conflicts * changes to loader file --------- Co-authored-by: Anthony D. Mays <[email protected]>
- Loading branch information
1 parent
a1bc9f7
commit 8cc7e02
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 HummadTanweerLoader implements Loader { | ||
getLoaderName(): string { | ||
return 'hummadtanweer'; | ||
} | ||
|
||
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 media = []; | ||
const readable = fs | ||
.createReadStream('data/media_items.csv', 'utf-8') | ||
.pipe(csv()); | ||
for await (const row of readable) { | ||
const { id, title, type, year: realeaseYear } = row; | ||
media.push(new MediaItem(id, title, type, realeaseYear, [])); | ||
} | ||
return media; | ||
} | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters