Created
December 27, 2018 21:41
-
-
Save soujiro32167/02ef0e838b9147580ea5bf2ac05bedc0 to your computer and use it in GitHub Desktop.
Teaching report for CSMB
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
function zip(a1, a2){if (a1.length > 0 && a2.length > 0) return [[a1.shift(), a2.shift()]].concat(zip(a1, a2)); else return []; }; | |
(function(){ | |
var rows = document.querySelectorAll('form table')[4].querySelectorAll('tr'); | |
var actualRows = [].slice.call(rows, 3, rows.length - 1).filter((r, i) => (i + 1) % 3 != 0); | |
var mappedRows = actualRows | |
.map(row => [].slice.call(row.querySelectorAll('td')) | |
.map(td => td.textContent.trim().replace(/\s/, " "))); | |
var evenRows = mappedRows.filter((r, i) => i % 2 == 0); | |
var oddRows = mappedRows.filter((r, i) => i % 2 != 0); | |
var zippedRows = zip(evenRows, oddRows); | |
var concatRows = zippedRows.map(([r1, r2]) => r1.concat(r2)); | |
var csvRows = concatRows.map(fields => fields.map(f => '"' + f + '"').join(",")); | |
$.getScript('https://s3-us-west-2.amazonaws.com/s.cdpn.io/14082/FileSaver.js', function(){ | |
console.log('saving to file...'); | |
var headers = [["Numéro de tâche", "Date/heure de début", "Lieu de travail", "Employé remplaçant", "status" , "Date/heure de fin", "Corps d'emploi", "Jours ouvrables"]]; | |
csvRows = headers.concat(csvRows); | |
var file = "\uFEFF" + csvRows.join("\n"); | |
var blob = new Blob([file], {type: "text/csv;charset=uft-8"}); | |
var d = new Date(); | |
var filename = `teaching_report_${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}.csv`; | |
saveAs(blob, filename); | |
}); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment