Last active
April 27, 2016 15:15
-
-
Save dotspencer/021bc8daf19323cf7a33d3c7cd7ad11c 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
<script src="http://papaparse.com/resources/js/papaparse.js"></script> | |
<input type="file" id="file-input" /> | |
<script type="text/javascript"> | |
window.onload = function(){ | |
main() | |
} | |
function main(){ | |
var finput = document.getElementById('file-input'); | |
var file; | |
var config = { | |
delimiter: ",", // auto-detect | |
newline: "", // auto-detect | |
header: false, | |
dynamicTyping: false, | |
preview: 0, | |
encoding: "", | |
step: undefined, | |
complete: dataLoaded, | |
} | |
function readFile() { | |
file = finput.files[0]; | |
console.log(file.size); | |
var p = Papa.parse(file, config); | |
console.log(p); | |
} | |
function dataLoaded(results){ | |
var body = document.body; | |
var data = results.data; | |
console.log(data[6]); | |
body.innerHTML += "<h2>" + data[1][1] + "<h2>"; | |
body.innerHTML += "<h3>Mailchimp Statistics</h3>"; | |
body.innerHTML += "<p><span class='first'>" + data[6][0] + "</span>" + data[6][1] + "</p>"; // Total Recipents | |
body.innerHTML += "<p><span class='first'>" + data[12][0] + "</span>" + data[12][1] + "</p>"; // Total Opens | |
body.innerHTML += "<p><span class='first'>" + data[15][0] + "</span>" + data[15][1] + "</p>"; // Total Clicks | |
body.innerHTML += "<p><span class='first'>" + data[8][0] + "</span>" + data[8][1] + "</p>"; // Bounced | |
body.innerHTML += "<h3>Top Articles</h3>"; | |
} | |
finput.addEventListener("change", readFile); | |
} | |
</script> | |
<style> | |
body{ | |
font-family: Helvetica; | |
} | |
span.first { | |
width: 150px; | |
display: inline-block; | |
} | |
@media print | |
{ | |
#file-input{ | |
display: none; | |
} | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment