Last active
March 26, 2026 18:29
-
-
Save battis/d70e8d814c92acd4d609c5d9b45182bf to your computer and use it in GitHub Desktop.
Convert a CSV of HTML snippets into a CSV of plain text snippets
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
| import { parse } from 'csv-parse/sync'; | |
| import { convert } from 'html-to-text'; | |
| import { stringify } from 'csv-stringify/sync'; | |
| import fs from 'node:fs'; | |
| const comments = parse( | |
| fs.readFileSync('/Users/sbattis/Downloads/comments.csv'), | |
| { | |
| columns: true, | |
| } | |
| ); | |
| const txt = comments.map((comment) => ({ | |
| 'Person ID': comment['Person ID'], | |
| 'Internal Class ID': comment['Internal Class ID'], | |
| 'Grading Period': comment['Grading Period'], | |
| Comment: convert(comment.Comment, { | |
| wordwrap: false, | |
| }), | |
| })); | |
| fs.writeFileSync( | |
| '/Users/sbattis/Downloads/comments-txt.csv', | |
| stringify(txt, { | |
| header: true, | |
| }) | |
| ); |
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
| import { parse } from 'csv-parse/sync'; | |
| import { convert } from 'html-to-text'; | |
| import { stringify } from 'csv-stringify/sync'; | |
| import fs from 'node:fs'; | |
| const courses = parse( | |
| fs.readFileSync('/Users/sbattis/Downloads/courses.csv'), | |
| { | |
| columns: true | |
| } | |
| ); | |
| const txt = courses.map( | |
| course => ({ | |
| 'Course ID': course['Course ID'], | |
| Description: convert( | |
| course.Description, | |
| { | |
| wordwrap: false | |
| } | |
| ) | |
| }) | |
| ); | |
| fs.writeFileSync( | |
| '/Users/sbattis/Downloads/courses-txt.csv', | |
| stringify( | |
| txt, | |
| { | |
| header: true | |
| } | |
| ) | |
| ); |
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
| import { stringify } from 'csv-stringify/sync'; | |
| import fs from 'node:fs'; | |
| const rosters = JSON.parse( | |
| fs.readFileSync( | |
| '/Users/sbattis/Library/CloudStorage/[email protected]/Shared drives/myGroton SIS Data/Athletics Implementation/2026-03-26 2025-2026 rosters.json', | |
| 'utf8' | |
| ) | |
| ); | |
| const data = []; | |
| for (const roster of rosters) { | |
| const { lead_section_id } = roster.section; | |
| for (const entry of roster.roster) { | |
| if (entry.player) { | |
| const { id: user_id, ...user } = entry.user; | |
| const { large_filename_url, thumb_filename_url } = entry.photo; | |
| data.push({ | |
| lead_section_id, | |
| user_id, | |
| ...user, | |
| large_filename_url, | |
| thumb_filename_url, | |
| ...entry.player, | |
| start: entry.enroll_date, | |
| end: entry.depart_date, | |
| status: entry.status, | |
| }); | |
| } | |
| } | |
| } | |
| fs.writeFileSync( | |
| '/Users/sbattis/Downloads/rosters.csv', | |
| stringify(data, { | |
| header: true, | |
| }) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment