From bf8ddc46e95a89da5b2f320418a3e3f4bd9a1926 Mon Sep 17 00:00:00 2001 From: BSanchidrian Date: Sat, 9 Nov 2024 15:15:38 +0100 Subject: [PATCH] Crawler formatting --- .../DanaCrawler/GoogleSheetService.cs | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/tools/DanaCrawler/DanaCrawler/GoogleSheetService.cs b/tools/DanaCrawler/DanaCrawler/GoogleSheetService.cs index e79fbb5f..87741cb2 100644 --- a/tools/DanaCrawler/DanaCrawler/GoogleSheetService.cs +++ b/tools/DanaCrawler/DanaCrawler/GoogleSheetService.cs @@ -1,5 +1,4 @@ -using System.Text.Json; -using Google.Apis.Auth.OAuth2; +using Google.Apis.Auth.OAuth2; using Google.Apis.Services; using Google.Apis.Sheets.v4; using Google.Apis.Sheets.v4.Data; @@ -34,10 +33,18 @@ public async Task InsertHelpRequests(List requests) private async Task InsertOffersRequestsAsync(List requests) { + var sheetName = "OfreceCRMV2"; + var clearRequest = _sheetsService.Spreadsheets.Values.Clear( + new ClearValuesRequest(), + _spreadsheetId, + $"{sheetName}!A1:ZZ" + ); + await clearRequest.ExecuteAsync(); + var headerRow = new List { - "Created At", "ID", "Status", "Town","Description", "Help Types", "Availability", "Vehicle", - "Number of People", "Name", "Location", "ContactInfo", "People Needed", + "Created At", "ID", "Status", "Town","Description", "Help Types", "L", "M", "X", "J", "V", "S", "D", + "Vehicle", "Number of People", "Name", "Location", "ContactInfo", "People Needed", }; var offerRequests = requests.Where(x => x.Type == "ofrece"); @@ -52,7 +59,13 @@ private async Task InsertOffersRequestsAsync(List requests) request.Town?.Name ?? "", request.Description ?? "", string.Join(", ", request.HelpType ?? []), - string.Join(", ", request.Resources?.Availability ?? []), + request.Resources != null ? request.Resources.Availability.Contains("Lunes") ? "X" : "" : "", + request.Resources != null ? request.Resources.Availability.Contains("Martes") ? "X" : "" : "", + request.Resources != null ? request.Resources.Availability.Contains("Miércoles") ? "X" : "" : "", + request.Resources != null ? request.Resources.Availability.Contains("Jueves") ? "X" : "" : "", + request.Resources != null ? request.Resources.Availability.Contains("Viernes") ? "X" : "" : "", + request.Resources != null ? request.Resources.Availability.Contains("Sábado") ? "X" : "" : "", + request.Resources != null ? request.Resources.Availability.Contains("Domingo") ? "X" : "" : "", request.Resources?.Vehicle ?? "NO", request.NumberOfPeople ?? 0, request.Name ?? "", @@ -73,7 +86,7 @@ private async Task InsertOffersRequestsAsync(List requests) var updateRequest = _sheetsService.Spreadsheets.Values.Update( valueRange, _spreadsheetId, - "OfreceCRMV2!A1:O" + $"{sheetName}!A1:S" ); updateRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; @@ -82,6 +95,14 @@ private async Task InsertOffersRequestsAsync(List requests) private async Task InsertNeedsRequestsAsync(List requests) { + string sheetName = "NecesitaCRMV2"; + var clearRequest = _sheetsService.Spreadsheets.Values.Clear( + new ClearValuesRequest(), + _spreadsheetId, + $"{sheetName}!A2:ZZ" + ); + await clearRequest.ExecuteAsync(); + var headerRow = new List { "Created At", "ID", "Status", "Town","Description", "Help Types", "Number of People", @@ -116,7 +137,7 @@ private async Task InsertNeedsRequestsAsync(List requests) var updateRequest = _sheetsService.Spreadsheets.Values.Update( valueRange, _spreadsheetId, - "NecesitaCRMV2!A1:O" + $"{sheetName}!A1:K" ); updateRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;