commit 8e78069fca467f206061a7432ff4dd00f26adc1f Author: Lynnesbian Date: Sat Sep 26 21:30:15 2020 +1000 init commit - rudimentary parsing format for me bank statements diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..99f7018 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea/ +bin/ +obj/ +test.csv diff --git a/Bank.cs b/Bank.cs new file mode 100644 index 0000000..974c318 --- /dev/null +++ b/Bank.cs @@ -0,0 +1,6 @@ +namespace BunyMuny { + public enum Bank { + ME, + NAB + } +} diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..cd3ef8d --- /dev/null +++ b/Program.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using CsvHelper; +using BunyMuny; + +namespace BunyMuny { + class Program { + static int Main(string[] args) { + Bank bank = Bank.ME; + var statements = new List(); + + using (var sr = new StreamReader("/mnt/code/cs/bunymuny/test.csv")) { + 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; + } + } + + foreach (var statement in statements) { + Console.WriteLine(statement); + } + } + } + + return 0; + } + } +} diff --git a/Statement.cs b/Statement.cs new file mode 100644 index 0000000..585a03d --- /dev/null +++ b/Statement.cs @@ -0,0 +1,14 @@ +using System; + +namespace BunyMuny { + public class Statement { + public DateTime Date; + public string Description; + public double Value; + public string Category; + + public override string ToString() { + return $"${Math.Abs(Value)} {(Value < 0 ? "to" : "from")} {Description} on {Date.ToString("MMM d yyyy")}"; + } + } +} diff --git a/bunymuny.csproj b/bunymuny.csproj new file mode 100644 index 0000000..9a396eb --- /dev/null +++ b/bunymuny.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + + + + + + +