Skip to content

Commit

Permalink
Crawler formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
BSanchidrian committed Nov 9, 2024
1 parent f71cbed commit bf8ddc4
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions tools/DanaCrawler/DanaCrawler/GoogleSheetService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,10 +33,18 @@ public async Task InsertHelpRequests(List<HelpRequest> requests)

private async Task InsertOffersRequestsAsync(List<HelpRequest> requests)
{
var sheetName = "OfreceCRMV2";
var clearRequest = _sheetsService.Spreadsheets.Values.Clear(
new ClearValuesRequest(),
_spreadsheetId,
$"{sheetName}!A1:ZZ"
);
await clearRequest.ExecuteAsync();

var headerRow = new List<object>
{
"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");
Expand All @@ -52,7 +59,13 @@ private async Task InsertOffersRequestsAsync(List<HelpRequest> 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 ?? "",
Expand All @@ -73,7 +86,7 @@ private async Task InsertOffersRequestsAsync(List<HelpRequest> requests)
var updateRequest = _sheetsService.Spreadsheets.Values.Update(
valueRange,
_spreadsheetId,
"OfreceCRMV2!A1:O"
$"{sheetName}!A1:S"
);
updateRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;

Expand All @@ -82,6 +95,14 @@ private async Task InsertOffersRequestsAsync(List<HelpRequest> requests)

private async Task InsertNeedsRequestsAsync(List<HelpRequest> requests)
{
string sheetName = "NecesitaCRMV2";
var clearRequest = _sheetsService.Spreadsheets.Values.Clear(
new ClearValuesRequest(),
_spreadsheetId,
$"{sheetName}!A2:ZZ"
);
await clearRequest.ExecuteAsync();

var headerRow = new List<object>
{
"Created At", "ID", "Status", "Town","Description", "Help Types", "Number of People",
Expand Down Expand Up @@ -116,7 +137,7 @@ private async Task InsertNeedsRequestsAsync(List<HelpRequest> requests)
var updateRequest = _sheetsService.Spreadsheets.Values.Update(
valueRange,
_spreadsheetId,
"NecesitaCRMV2!A1:O"
$"{sheetName}!A1:K"
);
updateRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;

Expand Down

0 comments on commit bf8ddc4

Please sign in to comment.