<commit_before>fs = require 'fs'

jsonFile = process.argv[2]

if !jsonFile?
  console.error "No JSON file specified"
  process.exit 1

if !jsonFile.match /\.json$/
  console.error "JSON file must end in .json"
  process.exit 2

try
  json = JSON.parse fs.readFileSync(jsonFile)
catch e
  console.error "Could not decode JSON"
  process.exit 3

statements = []
for name, statement of json
  statement.date = new Date(Date.parse(statement.date))
  statements.push statement

statements.sort (a, b) -> a.date - b.date

qif = "!Type:Bank\n"
for statement in statements
  for row in statement.rows
    #console.log "+ #{row.in} - #{row.out} = #{row.balance}"
    desc = row.details ? row.description
    desc = desc.replace /\n/g, " | "
    date = new Date(Date.parse("#{row.date} #{statement.date.getFullYear()}"))
    if +date > +statement.date + 1000 * 60 * 60 * 24 * 31
      date.setFullYear(date.getFullYear()-1)
    qif += "D#{date.toISOString().substr(0,10)}\n"<commit_msg>Improve QIF exporter.<commit_after>fs = require 'fs'

jsonFile = process.argv[2]

if !jsonFile?
  console.error "No JSON file specified"
  process.exit 1

if !jsonFile.match /\.json$/
  console.error "JSON file must end in .json"
  process.exit 2

try
  json = JSON.parse fs.readFileSync(jsonFile)
catch e
  console.error "Could not decode JSON"
  process.exit 3

# Fix all the dates.
statements = []
for name, statement of json
  statement.date = new Date(Date.parse(statement.date)+1000*60*60*12)
  for row in statement.rows
    date = new Date(Date.parse("#{row.date} #{statement.date.getFullYear()}")+1000*60*60*12)
    if +date > +statement.date + 1000 * 60 * 60 * 24 * 31
      date.setFullYear(date.getFullYear()-1)
    row.date = date
  statements.push statement

statements.sort (a, b) -> a.date - b.date

qif = "!Account\n"
name = statements[0].accountName.replace(/\s+,/g, ",").replace(/\s+/g, " ")
qif += "N#{name}\n"
qif += "TBank\n"
qif += "^\n"
qif += "!Type:Bank\n"

date = statements[0].rows[0].date
qif += "D#{date.toISOString().substr(0,10)}"
qif += "POpening Balance\n"
qif += "T#{statements[0].openingBalance/100}\n"
qif += "^\n"
for statement in statements
  for row in statement.rows
    #console.log "+ #{row.in} - #{row.out} = #{row.balance}"
    desc = row.details ? row.description
    desc = desc.replace /\n/g, " | "
    desc = desc.replace /\s+/g, " "
    qif += "D#{row.date.toISOString().substr(0,10)}\n"
{'fraction_non_alphanumeric': 0.1720563847429519, 'fraction_numerical': 0.02902155887230514, 'mean_word_length': 3.4934823091247673, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6910421', 'n_tokens_mistral': 933, 'n_tokens_neox': 875, 'n_words': 216}