From c7750ac4ca4cc161a4362161c23f7c43296a7ca5 Mon Sep 17 00:00:00 2001 From: akinayturan Date: Wed, 4 Mar 2026 23:06:50 +0300 Subject: [PATCH] Add total records tracking and update progress logging in vehicle detail retrieval --- src/HsnTsnScraper/Program.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/HsnTsnScraper/Program.cs b/src/HsnTsnScraper/Program.cs index f557b2c..1b7aa17 100644 --- a/src/HsnTsnScraper/Program.cs +++ b/src/HsnTsnScraper/Program.cs @@ -37,6 +37,7 @@ async Task RunRepairYearsMode(HsnTsnClient hsnTsnClient, string? inputPath, stri var processed = 0; var failed = 0; var updated = 0; + var totalRecords = Math.Max(0, File.ReadLines(inputCsvPath).Count() - 1); await using var inputStream = File.OpenRead(inputCsvPath); using var inputReader = new StreamReader(inputStream); @@ -69,7 +70,7 @@ async Task RunRepairYearsMode(HsnTsnClient hsnTsnClient, string? inputPath, stri { try { - var detail = await GetVehicleDetailWithRetry(hsnTsnClient, record.SourceDetailUrl, record.HsnTsn); + var detail = await GetVehicleDetailWithRetry(hsnTsnClient, record.SourceDetailUrl, record.HsnTsn, processed, totalRecords); if (detail is not null) { if (record.YearFrom is null && detail.YearFrom is not null) @@ -104,12 +105,12 @@ async Task RunRepairYearsMode(HsnTsnClient hsnTsnClient, string? inputPath, stri if (processed % 250 == 0) { await csvWriter.FlushAsync(); - Console.Error.WriteLine($"[info] Repair progress: processed={processed}, updated={updated}, failed={failed}"); + Console.Error.WriteLine($"[info] Repair progress: {processed}/{totalRecords}, updated={updated}, failed={failed}"); } } await csvWriter.FlushAsync(); - Console.Error.WriteLine($"[info] Repair finished. processed={processed}, updated={updated}, failed={failed}"); + Console.Error.WriteLine($"[info] Repair finished. {processed}/{totalRecords}, updated={updated}, failed={failed}"); } async Task RunScrapeMode(HsnTsnClient hsnTsnClient, bool includeDetailPages) @@ -203,7 +204,7 @@ async Task RunScrapeMode(HsnTsnClient hsnTsnClient, bool includeDetailPages) { try { - var detail = await GetVehicleDetailWithRetry(hsnTsnClient, vehicle.SourceDetailUrl, vehicle.HsnTsn); + var detail = await GetVehicleDetailWithRetry(hsnTsnClient, vehicle.SourceDetailUrl, vehicle.HsnTsn, null, null); if (detail is not null) { if (!string.IsNullOrWhiteSpace(detail.Brand)) @@ -265,10 +266,17 @@ static string? GetOptionValue(string[] cliArgs, string optionName) return null; } -async Task GetVehicleDetailWithRetry(HsnTsnClient hsnTsnClient, string detailUrl, string hsnTsn) +async Task GetVehicleDetailWithRetry(HsnTsnClient hsnTsnClient, string detailUrl, string hsnTsn, int? currentIndex, int? totalCount) { const int maxAttempts = 7; - Console.Error.WriteLine($"[info] Fetching detail for HSN/TSN: {hsnTsn}"); + if (currentIndex is not null && totalCount is not null && totalCount > 0) + { + Console.Error.WriteLine($"[info] [{currentIndex}/{totalCount}] Fetching detail for HSN/TSN: {hsnTsn}"); + } + else + { + Console.Error.WriteLine($"[info] Fetching detail for HSN/TSN: {hsnTsn}"); + } for (var attempt = 1; attempt <= maxAttempts; attempt++) {