using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.CommandLine.DragonFruit; using CsvHelper; using CsvHelper.Configuration.Attributes; namespace BunyMuny { class Program { /// /// BunyMuny parses the CSV output of various bank statement listings and converts it to something more human readable with nice visualisations. /// /// The CSV file to read /// The JSON file to use for rules when parsing statement descriptions /// static int Main(string file = "test.csv", string rules = "rules.json") { Bank bank = Bank.ME; var statements = new List(); using (var sr = new StreamReader(file)) { using (var csv = new CsvReader(sr, CultureInfo.InvariantCulture)) { csv.Read(); csv.ReadHeader(); // get the first line of the CSV file (the header) as a string string header = csv.Parser.Context.RawRecord; if (header == null) { Console.WriteLine("File is empty 0uo"); return 1; } else if (header == "Date,Description,Debits and credits,Balance") { bank = Bank.ME; } else if (header == "Whatever NAB uses I guess") { bank = Bank.NAB; } while (csv.Read()) { switch (bank) { case Bank.ME: double value = double.Parse(csv.GetField("Debits and credits").TrimStart().Replace("$", "")); statements.Add(new Statement() { Date = DateTime.ParseExact(csv.GetField("Date"), "dd/MM/yyyy", CultureInfo.InvariantCulture), Description = csv.GetField("Description"), Category = "Unknown", Value = value }); break; default: Console.WriteLine(":("); return 1; } } foreach (var statement in statements) { Console.WriteLine(statement); } } } return 0; } } }