Created
October 6, 2020 21:59
-
-
Save ogawa0071/f937d2a8738f96c34088b739c607a6d0 to your computer and use it in GitHub Desktop.
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 * as fs from "fs"; | |
| import csvParse from "csv-parse"; | |
| const textArray = [ | |
| "green", | |
| "aqua", | |
| "red", | |
| "purple", | |
| "olive", | |
| "yellow", | |
| "gray", | |
| "white", | |
| "navy", | |
| "blue", | |
| ]; | |
| (async () => { | |
| const startYear = 1950 - 1; | |
| const csv = await fs.promises.readFile(`csv.csv`); | |
| const result: { [key: string]: string } = {}; | |
| await new Promise((resolve) => { | |
| csvParse(csv, (_, records: string[][]) => { | |
| for (let rowIndex = 1; rowIndex < records.length + 1; rowIndex++) { | |
| const year = Math.ceil(rowIndex / 13) + startYear; | |
| const month = (rowIndex - 1) % 13; | |
| for ( | |
| let colIndex = 1; | |
| colIndex < records[rowIndex - 1].length + 1; | |
| colIndex++ | |
| ) { | |
| const day = colIndex - 1; | |
| const cell = records[rowIndex - 1][colIndex - 1]; | |
| if (year && month && day && textArray.find((text) => text === cell)) { | |
| // console.log(`${year}-${month}-${day}`, cell); | |
| result[ | |
| `${year}-${month | |
| .toString() | |
| .padStart(2, "0")}-${day.toString().padStart(2, "0")}` | |
| ] = cell; | |
| } | |
| } | |
| } | |
| resolve(); | |
| }); | |
| }); | |
| fs.promises.writeFile("result.json", JSON.stringify(result, null, 2)); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment