Skip to content

Commit

Permalink
Constants for file
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel0024 committed Jun 23, 2024
1 parent 4185178 commit 3dcd719
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion FundaScraper/App/FundaScraperBackgroundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
new(nameof(ListingModel.ZipCode), settings.Value.ZipCodeSelector)
])
.AddSink(webhookSink)
.AddSink(new CsvFileSink(Path.Combine("/data", "results.csv"), dataCleanupOnStart: true))
.AddSink(new CsvFileSink(Constants.FileNames.ResultsFilePath, dataCleanupOnStart: true))
.WithParallelismDegree(settings.Value.ParallelismDegree)
.PageCrawlLimit(settings.Value.PageCrawlLimit);

Expand Down
10 changes: 5 additions & 5 deletions FundaScraper/App/WebhookDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace FundaScraper.App;

internal class WebhookDB
{
private readonly string DatabaseFilePath = Path.Combine("/data", "webhooks-history.json");
private readonly string WebhooksHistoryJson = Constants.FileNames.WebhooksHistoryJson;
private Dictionary<string, ListingModel> Listings { get; init; }

public WebhookDB()
Expand All @@ -26,14 +26,14 @@ internal async Task SaveWebHook(ListingModel entry)

private async Task<DbModel> GetHistoryFile()
{
if (!File.Exists(DatabaseFilePath))
if (!File.Exists(WebhooksHistoryJson))
{
return new DbModel([]);
}

try
{
var json = await File.ReadAllTextAsync(DatabaseFilePath);
var json = await File.ReadAllTextAsync(WebhooksHistoryJson);
return JsonSerializer.Deserialize<DbModel>(json)!;
}
catch
Expand All @@ -46,9 +46,9 @@ private async Task SaveHistoryFile(DbModel model)
{
var json = JsonSerializer.Serialize(model);

Directory.CreateDirectory(Path.GetDirectoryName(DatabaseFilePath)!);
Directory.CreateDirectory(Path.GetDirectoryName(WebhooksHistoryJson)!);

await File.WriteAllTextAsync(DatabaseFilePath, json);
await File.WriteAllTextAsync(WebhooksHistoryJson, json);
}
}

Expand Down
2 changes: 1 addition & 1 deletion FundaScraper/App/WebhookSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task EmitAsync(ParsedData entity, CancellationToken cancellationTok

try
{
listingModel = JsonSerializer.Deserialize<ListingModel>(entity.Data.ToString());
listingModel = JsonSerializer.Deserialize<ListingModel>(entity.Data.ToString())!;
}
catch { return; }

Expand Down
10 changes: 10 additions & 0 deletions FundaScraper/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace FundaScraper;

internal static class Constants
{
internal static class FileNames
{
internal static string WebhooksHistoryJson = Path.Combine("/data", "webhooks-history.json");
internal static string ResultsFilePath = Path.Combine("/data", "results.csv");
}
}

0 comments on commit 3dcd719

Please sign in to comment.