Skip to content

Instantly share code, notes, and snippets.

@mateusg
Last active May 31, 2016 00:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mateusg/3d6eb6befc778d85d6b3 to your computer and use it in GitHub Desktop.
Save mateusg/3d6eb6befc778d85d6b3 to your computer and use it in GitHub Desktop.
var parseDate = function(date) {
var year = 2000 + parseInt($('.period .filter').text().match(/^.*(\d{2})$/)[1])
date = date
.replace('Fev', 'Feb')
.replace('Abr', 'Apr')
.replace('Mai', 'May')
.replace('Ago', 'Aug')
.replace('Set', 'Sep')
.replace('Out', 'Oct')
.replace('Dez', 'Dec');
return new Date(Date.parse(date + " " + year))
}
var formatCSVRow = function(transaction) {
var time = parseDate(transaction.time).toLocaleString('en').match(/\d+\/\d+\/\d+/)[0],
type = transaction.type,
category = transaction.category,
description = transaction.description,
amount = parseFloat(transaction.amount.replace('.', '').replace(',', '.').replace('R$', '')),
tags = transaction.tags;
return [time, type, category, description, amount, tags].join(',');
}
var events = []
$('#feedTable .event-card').each(function() {
var $this = $(this)
events.push({
time: $this.find('.time').text(),
type: $this.find('.type').text(),
category: $this.find('.title').text(),
description: $this.find('.description').text(),
amount: $this.find('.amount').text(),
tags: $this.find('.tags .tag').map(function(){ return $(this).text() }).toArray().join(';')
})
})
var csvRows = events.map(function(e) { return formatCSVRow(e) }).reverse()
csvRows.unshift('Time,Type,Category,Description,Amount,Tags');
console.log(csvRows.join("\r\n"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment