3
3
using Arctic . Puzzlers . Stores ;
4
4
using HtmlAgilityPack ;
5
5
using Microsoft . Extensions . Logging ;
6
+ using System . Diagnostics ;
6
7
using System . Globalization ;
7
8
using System . Text . RegularExpressions ;
8
9
using System . Xml . Linq ;
@@ -42,12 +43,20 @@ public async Task Parse(string baseurl)
42
43
{
43
44
continue ;
44
45
}
46
+
47
+ var competitionName = competitionPage . DocumentNode . SelectNodes ( "//p[contains(@class,'nombre_campeonato')]" ) ;
45
48
var listOfRounds = competitionPage . DocumentNode . SelectNodes ( "//nav[contains(@class,'nav-underline')]/a" ) ;
49
+ var competition = new Competition ( ) ;
50
+ if ( competitionName != null && competitionName . Count ( ) == 1 )
51
+ {
52
+ competition . Name = competitionName [ 0 ] . InnerText ;
53
+ }
54
+
46
55
47
56
var individualRounds = listOfRounds . Where ( t => t . GetAttributeValue ( "href" , "" ) . ToLower ( ) . Contains ( "individual" ) ) ;
48
57
var pairRounds = listOfRounds . Where ( t => t . GetAttributeValue ( "href" , "" ) . ToLower ( ) . Contains ( "pairs" ) ) ;
49
58
var teamRounds = listOfRounds . Where ( t => t . GetAttributeValue ( "href" , "" ) . ToLower ( ) . Contains ( "teams" ) ) ;
50
- var competition = new Competition ( ) ;
59
+
51
60
competition . Url = competitionUrl ;
52
61
if ( individualRounds . Any ( ) )
53
62
{
@@ -184,7 +193,8 @@ private async Task<CompetitionGroup> AddRound(string baseUrl, IEnumerable<HtmlNo
184
193
185
194
competitionRound . RoundType = competitionRound . RoundName . ToLower ( ) == "final" ? RoundType . Final : competitionRound . RoundName . ToLower ( ) . StartsWith ( 's' ) ? RoundType . Semifinal : RoundType . Qualification ;
186
195
var placeAndTime = doc . DocumentNode . SelectSingleNode ( "//p[@class='lead']" ) . InnerText ;
187
-
196
+ var date = doc . DocumentNode . SelectNodes ( "//span[contains(i/@class,'bi-calendar3')]" ) ;
197
+ var clock = doc . DocumentNode . SelectNodes ( "//span[contains(i/@class,'bi-clock')]" ) ;
188
198
if ( ! string . IsNullOrEmpty ( placeAndTime ) )
189
199
{
190
200
var placeAndTimeList = placeAndTime . Split ( '.' , 2 ) ;
@@ -194,9 +204,36 @@ private async Task<CompetitionGroup> AddRound(string baseUrl, IEnumerable<HtmlNo
194
204
if ( DateTime . TryParseExact ( datetimeString , "dd/MM/yyyy-HH:mm" , CultureInfo . CurrentCulture , DateTimeStyles . None , out DateTime time ) )
195
205
{
196
206
competitionRound . Time = time ;
197
- }
207
+ }
198
208
competitionRound . Location = placeAndTimeList [ 1 ] ;
199
209
}
210
+ else if ( placeAndTimeList . Length == 1 )
211
+ {
212
+ competitionRound . Location = placeAndTimeList [ 0 ] ;
213
+ }
214
+ }
215
+
216
+ if ( date != null && date . Count == 1 && clock != null && clock . Count == 1 )
217
+ {
218
+ var datetimestring = date [ 0 ] . InnerText + "-" + clock [ 0 ] . InnerText ;
219
+ datetimestring = datetimestring . Replace ( " " , string . Empty ) ;
220
+ if ( DateTime . TryParseExact ( datetimestring , "dd/MM/yyyy-HH:mm" , CultureInfo . CurrentCulture , DateTimeStyles . None , out DateTime timeFromText ) )
221
+ {
222
+ competitionRound . Time = timeFromText ;
223
+ }
224
+ }
225
+
226
+
227
+ var maxTime = doc . DocumentNode . SelectNodes ( "//span[contains(i/@class,'bi-stopwatch')]" ) ;
228
+ if ( maxTime != null && maxTime . Count == 1 && TimeSpan . TryParse ( CleanUpString ( maxTime [ 0 ] . InnerText ) , out TimeSpan maxTimeSpan ) )
229
+ {
230
+ competitionRound . MaxTime = maxTimeSpan ;
231
+ }
232
+
233
+ var pieceCount = doc . DocumentNode . SelectNodes ( "//span[contains(i/@class,'bi-puzzle')]" ) ;
234
+ if ( pieceCount != null && pieceCount . Count == 1 && int . TryParse ( CleanUpString ( pieceCount [ 0 ] . InnerText ) , out int pieceCountOut ) )
235
+ {
236
+ competitionRound . NumberOfPieces = pieceCountOut ;
200
237
}
201
238
int namefield = 3 ;
202
239
int timefield = 7 ;
@@ -247,5 +284,12 @@ public bool TryResolveCompetitionUrl(string baseUrl, HtmlNode node, out string c
247
284
currentUrl += node . GetAttributeValue ( "href" , "" ) ;
248
285
return true ;
249
286
}
287
+
288
+ private string CleanUpString ( string value )
289
+ {
290
+ value = value . Replace ( " " , string . Empty ) ;
291
+ value = value . Replace ( " " , string . Empty ) ;
292
+ return value ;
293
+ }
250
294
}
251
295
}
0 commit comments