-
Notifications
You must be signed in to change notification settings - Fork 25
Chigazo Lesson 10 Media Loader #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
887b8f0
Merge pull request #1 from code-differently/main
A1-4U2T1NN 05ad627
Merge branch 'code-differently:main' into main
A1-4U2T1NN 5715b6a
Merge branch 'code-differently:main' into main
A1-4U2T1NN 6c909b0
Merge branch 'code-differently:main' into main
A1-4U2T1NN 4c1a3f2
Merge branch 'code-differently:main' into main
A1-4U2T1NN de19403
Merge branch 'code-differently:main' into main
A1-4U2T1NN 56aa83d
Merge branch 'code-differently:main' into main
A1-4U2T1NN 8529105
Merge branch 'code-differently:main' into main
A1-4U2T1NN 4f76813
Merge branch 'code-differently:main' into main
A1-4U2T1NN 48bf962
Merge branch 'code-differently:main' into main
A1-4U2T1NN 1da88b9
Merge branch 'code-differently:main' into main
A1-4U2T1NN 3068765
Merge branch 'code-differently:main' into main
A1-4U2T1NN 712efd6
Merge branch 'code-differently:main' into main
A1-4U2T1NN 5db7413
Merge branch 'code-differently:main' into main
A1-4U2T1NN 5096f8e
Merge branch 'code-differently:main' into main
A1-4U2T1NN 09341aa
Merge branch 'code-differently:main' into main
A1-4U2T1NN a8f634e
Merge branch 'code-differently:main' into main
A1-4U2T1NN b643a4c
feat: created chigazograham.json file
cae2152
Merge branch 'code-differently:main' into main
A1-4U2T1NN 68ccb5f
fix: deleted lesson_09 content from main;
bfc22bf
Merge branch 'code-differently:main' into lesson_10
A1-4U2T1NN 26aa2b9
feat: added loader file into loaders Folder; added loader provider to…
b0580aa
Merge branch 'code-differently:main' into lesson_10
A1-4U2T1NN 3e8bd38
feat: added chigazo_graham_loader.ts file with completed media loader…
0cf5223
Merge branch 'lesson_10' of https://github.com/A1-4U2T1NN/code-differ…
95771a9
chore: converted .pipe csv into manual csv parser;
35b501f
fix: corrected creating a new line for every variable within array;
fcbf22c
feat: added id to row array;
36a334d
chore: made lesson_10 and lesson_10 extra credit seperate branches;
a694891
fix: recreated loader from a previous commit;
6d0d2bf
fix: removed id from row array;
6790a90
chore removed lesson_09 package.json; removed TODO comment;
75f3eee
feat: added 'id' back into row and new media item;
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,5 @@ | ||
{ | ||
"dependencies": { | ||
"csv-parser": "^3.0.0" | ||
} | ||
} |
This file contains hidden or 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,46 @@ | ||
import csv from 'csv-parser'; | ||
import fs from 'fs'; | ||
import { Credit, MediaItem } from '../models/index.js'; | ||
import { Loader } from './loader.js'; | ||
|
||
export class ChigazoGrahamLoader implements Loader { | ||
getLoaderName(): string { | ||
return 'chigazograham'; | ||
} | ||
|
||
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[]> { | ||
// TODO: Implement this method. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this comment. |
||
const mediaItems = []; | ||
const readable = fs | ||
.createReadStream('data/media_items.csv', 'utf-8') | ||
.pipe(csv()); | ||
for await (const row of readable) { | ||
const { type, title, genre, year } = row; | ||
mediaItems.push(new MediaItem(type, title, genre, 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; | ||
} | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete files you added for lesson_09