Skip to content

Commit 10ce387

Browse files
author
Andrii Bondarchuk
committed
Everesting
1 parent d910c0f commit 10ce387

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/FitSyncHub.Functions/Functions/EverestingHOFScraperHttpTriggerFunction.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Buffers;
22
using System.Text;
33
using System.Text.Json;
4+
using System.Text.Json.Serialization;
45
using System.Text.RegularExpressions;
56
using HtmlAgilityPack;
67
using Microsoft.AspNetCore.Http;
@@ -55,6 +56,7 @@ public async Task<IActionResult> Run(
5556
{
5657
var url = QueryHelpers.AddQueryString(BaseUrl, new Dictionary<string, StringValues>
5758
{
59+
{"order", "date_desc" },
5860
{"page", page.ToString() },
5961
});
6062

@@ -96,16 +98,12 @@ private static bool AllActiviesSynced(
9698
DateTime lastSyncedDateTime)
9799
{
98100
var activities = GetActivitiesArray(root);
99-
HashSet<DateTime> dates = [];
101+
var dtos = activities.EnumerateArray()
102+
.Select(x => x.Deserialize<ActivityItemProjection>())
103+
.ToList();
100104

101-
foreach (var activity in activities.EnumerateArray())
102-
{
103-
var date = activity.GetProperty("date");
104-
var dateParsed = DateTime.ParseExact(date.ToString(), "yyyy-MM-dd", null);
105-
dates.Add(dateParsed);
106-
}
107-
108-
return dates.All(d => d < lastSyncedDateTime);
105+
return dtos.Count != 0
106+
&& dtos.All(x => x is not null && x.Date != default && x.Date < lastSyncedDateTime);
109107
}
110108

111109
private async Task<DateTime> GetLastSynchronizedDate(CancellationToken cancellationToken)
@@ -240,6 +238,7 @@ private async Task StoreData(
240238

241239
private record ActivityItemProjection
242240
{
241+
[JsonPropertyName("date")]
243242
public DateTime Date { get; init; }
244243
}
245244
}

0 commit comments

Comments
 (0)