Skip to content

Commit d67b840

Browse files
authored
Merge pull request #201 from rprouse/issue/200
Download Enbridge bills
2 parents 3e09fd0 + 0fb09ae commit d67b840

File tree

7 files changed

+282
-51
lines changed

7 files changed

+282
-51
lines changed

Guppi.Console/Guppi.Console.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<PackageProjectUrl>https://github.com/rprouse/guppi</PackageProjectUrl>
1414
<RepositoryUrl>https://github.com/rprouse/guppi</RepositoryUrl>
1515
<PackageId>dotnet-guppi</PackageId>
16-
<Version>6.3.0</Version>
16+
<Version>6.3.1</Version>
1717
<PackAsTool>true</PackAsTool>
1818
<ToolCommandName>guppi</ToolCommandName>
1919
<PackageOutputPath>./nupkg</PackageOutputPath>

Guppi.Console/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"Guppi.Console": {
44
"commandName": "Project",
5-
"commandLineArgs": "bills alectra"
5+
"commandLineArgs": "bills all"
66
}
77
}
88
}

Guppi.Console/Skills/BillsSkill.cs

+35-5
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,39 @@ internal class BillsSkill(IBillService service) : ISkill
1616

1717
public IEnumerable<Command> GetCommands()
1818
{
19+
var option = new Option<int>(new string[] { "--months", "-m" }, () => 1, "The number of months of bills to download.");
20+
21+
var all = new Command("all", "Download bills from all providers")
22+
{
23+
option
24+
};
25+
all.Handler = CommandHandler.Create(async (int months) => await DownloadAllBills(months));
26+
1927
var alectra = new Command("alectra", "Download bills from Alectra")
2028
{
29+
option
30+
};
31+
alectra.Handler = CommandHandler.Create(async (int months) => await DownloadAlectraBills(months));
32+
33+
var enbridge = new Command("enbridge", "Download bills from Enbridge")
34+
{
35+
option
2136
};
22-
alectra.Handler = CommandHandler.Create(async () => await DownloadAlectraBills());
37+
enbridge.Handler = CommandHandler.Create(async (int months) => await DownloadEnbridgeBills(months));
2338

2439
var configure = new Command("configure", "Configures the Bill provider");
2540
configure.AddAlias("config");
2641
configure.Handler = CommandHandler.Create(() => Configure());
2742

43+
var install = new Command("install", "Installs Playwright for the Bill provider");
44+
install.Handler = CommandHandler.Create(() => _service.InstallPlaywright());
45+
2846
var command = new Command("bills", "Download bills from online")
2947
{
48+
all,
3049
alectra,
50+
enbridge,
51+
install,
3152
configure
3253
};
3354
command.AddAlias("billing");
@@ -36,13 +57,22 @@ public IEnumerable<Command> GetCommands()
3657
return new List<Command> { command };
3758
}
3859

39-
private async Task DownloadAlectraBills()
40-
{
60+
private async Task DownloadAllBills(int months) =>
61+
await DownloadBills(":spiral_notepad: Download Bills", months, _service.DownloadAllBills);
62+
63+
private async Task DownloadAlectraBills(int months) =>
64+
await DownloadBills(":high_voltage: Alectra Bills", months, _service.DownloadAlectraBills);
65+
66+
private async Task DownloadEnbridgeBills(int months) =>
67+
await DownloadBills(":chart_increasing: Enbridge Bills", months, _service.DownloadEnbridgeBills);
68+
69+
private static async Task DownloadBills(string title, int months, Func<int, Task> downloader)
70+
{
4171
try
4272
{
43-
AnsiConsoleHelper.TitleRule(":high_voltage: Alectra Bills");
73+
AnsiConsoleHelper.TitleRule(title);
4474

45-
await _service.DownloadAlectraBills();
75+
await downloader(months);
4676

4777
AnsiConsoleHelper.Rule("white");
4878
}

Guppi.Core/Interfaces/Services/IBillService.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ namespace Guppi.Core.Interfaces.Services;
44

55
public interface IBillService
66
{
7-
Task DownloadAlectraBills();
7+
Task DownloadAllBills(int months);
8+
Task DownloadAlectraBills(int months);
9+
Task DownloadEnbridgeBills(int months);
10+
void InstallPlaywright();
811
void Configure();
912
}
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using ClosedXML.Excel;
4+
5+
namespace Guppi.Core.Providers;
6+
7+
public class WorkbookProvider
8+
{
9+
readonly string _filename;
10+
readonly IXLWorkbook _workbook;
11+
readonly IXLWorksheet _worksheet;
12+
int row = 0;
13+
14+
/// <summary>
15+
/// Creates a new instance of the WorksheetProvider
16+
/// </summary>
17+
/// <param name="filename">The filename for the workbook</param>
18+
/// <param name="sheet">The name of the worksheet</param>
19+
/// <param name="delete">Deletes and recreates the workbook if it exists</param>
20+
public WorkbookProvider(string filename, string sheet, IEnumerable<string> headers, bool delete = true)
21+
{
22+
_filename = filename;
23+
24+
if (delete && File.Exists(_filename))
25+
{
26+
File.Delete(_filename);
27+
}
28+
29+
_workbook = new XLWorkbook();
30+
_worksheet = _workbook.Worksheets.Add("Bills");
31+
32+
AddRow(headers);
33+
}
34+
35+
public void AddRow(IEnumerable<string> values)
36+
{
37+
row++;
38+
int col = 1;
39+
foreach (string value in values) {
40+
_worksheet.Cell(row, col++).Value = value;
41+
}
42+
}
43+
44+
public void Save()
45+
{
46+
_workbook.SaveAs(_filename);
47+
}
48+
}

0 commit comments

Comments
 (0)