Compare commits
No commits in common. "9a1272c085cbd15a5d5ab44ab292dbcf9dcc9ee1" and "161ad4e2204d81555e44ffa8df04d972003fea66" have entirely different histories.
9a1272c085
...
161ad4e220
4 changed files with 28 additions and 19 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,4 +2,4 @@
|
|||
bin/
|
||||
obj/
|
||||
test.csv
|
||||
rules.csv
|
||||
rules.json
|
||||
|
|
21
Program.cs
21
Program.cs
|
@ -20,8 +20,10 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.CommandLine.DragonFruit;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using CsvHelper;
|
||||
|
||||
namespace BunyMuny {
|
||||
|
@ -30,16 +32,18 @@ namespace BunyMuny {
|
|||
/// BunyMuny parses the CSV output of various bank statement listings and converts it to something more human readable with nice visualisations.
|
||||
/// </summary>
|
||||
/// <param name="file">The CSV file to read</param>
|
||||
/// <param name="ruleFile">The CSV file to use for rules when parsing statement descriptions</param>
|
||||
/// <param name="ruleFile">The JSON file to use for rules when parsing statement descriptions</param>
|
||||
/// <returns></returns>
|
||||
private static int Main(string file = "test.csv", string ruleFile = "rules.csv") {
|
||||
private static int Main(string file = "test.csv", string ruleFile = "rules.json") {
|
||||
var bank = Bank.Other;
|
||||
var statements = new List<Statement>();
|
||||
List<Rule> rules;
|
||||
|
||||
using (var ruleStreamReader = new StreamReader(ruleFile)) {
|
||||
using var ruleCsv = new CsvReader(ruleStreamReader,CultureInfo.InvariantCulture);
|
||||
rules = ruleCsv.GetRecords<Rule>().ToList();
|
||||
var jsonOptions = new JsonSerializerOptions();
|
||||
jsonOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase));
|
||||
jsonOptions.WriteIndented = true;
|
||||
rules = JsonSerializer.Deserialize<List<Rule>>(ruleStreamReader.ReadToEnd(), jsonOptions);
|
||||
}
|
||||
|
||||
using var sr = new StreamReader(file);
|
||||
|
@ -69,13 +73,14 @@ namespace BunyMuny {
|
|||
switch (bank) {
|
||||
case Bank.ME:
|
||||
var value = double.Parse(csv.GetField("Debits and credits").TrimStart().Replace("$", ""));
|
||||
var (category, description) = MatchAgainstRules(rules, csv.GetField("Description"));
|
||||
// SHOW PET THIS
|
||||
var ruleValues = MatchAgainstRules(rules, csv.GetField("Description"));
|
||||
|
||||
statements.Add(new Statement() {
|
||||
Date = DateTime.ParseExact(csv.GetField("Date"), "dd/MM/yyyy", CultureInfo.InvariantCulture),
|
||||
OriginalDescription = csv.GetField("Description"),
|
||||
Description = description,
|
||||
Category = category,
|
||||
Description = ruleValues.Description,
|
||||
Category = ruleValues.Category,
|
||||
Value = value
|
||||
});
|
||||
break;
|
||||
|
@ -95,7 +100,7 @@ namespace BunyMuny {
|
|||
}
|
||||
|
||||
foreach (var statement in statements.
|
||||
// Where(s => s.Category != null).
|
||||
Where(s => s.Category != null).
|
||||
OrderBy(s => s.Date)) {
|
||||
Console.WriteLine(statement);
|
||||
}
|
||||
|
|
23
README.md
23
README.md
|
@ -13,19 +13,24 @@ dotnet build
|
|||
|
||||
## The rules file
|
||||
By default, BunyMuny checks for rules in `rules.json` in the current directory. An example rules file might look like this:
|
||||
```csv
|
||||
Match,Value,Category,Description,CaseSensitive
|
||||
Start,Purchase Cash Converters,Personal,Cashies,true
|
||||
```json
|
||||
[
|
||||
{
|
||||
"Match":"Start",
|
||||
"Value": "Purchase Cash Converters",
|
||||
"Category":"Personal",
|
||||
"Description":"Cashies"
|
||||
}
|
||||
]
|
||||
```
|
||||
This means that any statement that starts with "Purchase Cash Converters" (case sensitive) will be assigned the category "Personal", and the description "Cashies".
|
||||
This means that any statement that starts with "Purchase Cash Converters" will be assigned the category "Personal", and the description "Cashies".
|
||||
|
||||
- `Match` specifies the type of matching to perform. It can be any of the following:
|
||||
- `"Match"` specifies the type of matching to perform. It can be any of the following:
|
||||
- "Start": Match the start of the description.
|
||||
- "End": Match the end of the description.
|
||||
- "Contains": Match anywhere in the description.
|
||||
- "Exact": Only match if the bank statement's description is exactly equal to the provided value.
|
||||
- "Regex": Match with [regular expressions](https://en.wikipedia.org/wiki/Regular_expression).
|
||||
- `Value` specifies the value to match against.
|
||||
- `Category` is the category that the statement should be filed under.
|
||||
- `Description` is a short description to distinguish the particular merchant.
|
||||
- `CaseSensitive` specifies whether or not the match should be case sensitive.
|
||||
- `"Value"` specifies the value to match against.
|
||||
- `"Category"` is the category that the statement should be filed under.
|
||||
- `"Description"` is a short description to distinguish the particular merchant.
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<NoWarn>1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Reference in a new issue