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
const express = require('express'); | |
const fs = require('fs'); | |
const { JSDOM } = require('jsdom'); | |
const app = express(); | |
const HTML_FILE = 'index.html'; | |
const CSV_FILE = 'parsed.csv'; | |
const ONLY_ALPHA = /[^a-z']/gi; | |
const REMOVE_SPACES = / {2,}/g; | |
const SMALL = 1; | |
const MEDIUM = 3; | |
const LARGE = 5; | |
const stream = fs.createWriteStream(CSV_FILE); | |
fs.readFile(HTML_FILE, 'utf-8', (err, data) => { | |
stream.write(`label_column, text_column\n`); | |
const DOM = new JSDOM(data); | |
const rows = DOM.window.document.getElementsByTagName('tbody')[0].rows; | |
Array.from(rows).forEach(row => { | |
const title = row.cells[1].getElementsByTagName('p')[0].textContent.trim() | |
.replace(ONLY_ALPHA, ' ').replace(REMOVE_SPACES, ' '); | |
const storyPoints = row.cells[2].textContent.trim(); | |
const desc = row.cells[3].textContent.trim() | |
.replace(ONLY_ALPHA, ' ').replace(REMOVE_SPACES, ' '); | |
const newSP = storyPoints <= LARGE ? (storyPoints > SMALL && storyPoints <= MEDIUM) ? MEDIUM : SMALL : LARGE; | |
stream.write(`${newSP} , ${title} ${desc}\n`); | |
}); | |
stream.end(); | |
}); | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment