init commit - rudimentary parsing format for me bank statements

This commit is contained in:
Lynne Megido 2020-09-26 21:30:15 +10:00
commit 8e78069fca
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
5 changed files with 91 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
.idea/
bin/
obj/
test.csv

6
Bank.cs Normal file
View file

@ -0,0 +1,6 @@
namespace BunyMuny {
public enum Bank {
ME,
NAB
}
}

55
Program.cs Normal file
View file

@ -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<Statement>();
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;
}
}
}

14
Statement.cs Normal file
View file

@ -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")}";
}
}
}

12
bunymuny.csproj Normal file
View file

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CsvHelper" Version="15.0.6" />
</ItemGroup>
</Project>