@@ -12,31 +12,40 @@ export const getRaceSchedule = async (year: number = new Date().getFullYear()):
12
12
const response = await axios ( `${ dynamicLinks . raceSchedule } /${ year } .html` ) ;
13
13
const $ = cheerio . load ( response . data ) ;
14
14
15
- $ ( "a.outline-offset-4" ) . each ( function ( ) {
16
- const round : string = $ ( this ) . find ( "a.outline-offset-4 > fieldset:nth-child(1) > legend:nth-child(1) > p:nth-child(1)" ) . text ( ) . trim ( ) ;
17
- const dateDays1 : string = $ ( this ) . find ( "div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > p:nth-child(1) > span:nth-child(1)" ) . text ( ) . trim ( ) ;
18
- const dateDays2 : string = $ ( this ) . find ( "div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > p:nth-child(1) > span:nth-child(1)" ) . text ( ) . trim ( ) ;
19
- const dateMonth1 : string = $ ( this ) . find ( "div:nth-child(2) > div:nth-child(1) > div:nth-child(2) > p:nth-child(1) > span:nth-child(1)" ) . text ( ) . trim ( ) ;
20
- const dateMonth2 : string = $ ( this )
21
- . find ( "div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > span:nth-child(1) > span:nth-child(1)" )
22
- . text ( )
23
- . trim ( ) ;
24
- const raceCountry : string = $ ( this )
25
- . find ( "a.outline-offset-4 > fieldset:nth-child(1) > div:nth-child(2) > div:nth-child(3) > div:nth-child(1) > p:nth-child(1)" )
26
- . text ( )
27
- . trim ( ) ;
28
- const eventTitle : string = $ ( this )
29
- . find ( "a.outline-offset-4 > fieldset:nth-child(1) > div:nth-child(2) > div:nth-child(3) > div:nth-child(2) > p:nth-child(1)" )
30
- . text ( )
31
- . trim ( ) ;
32
-
33
- const dateDays = dateDays1 || dateDays2 ;
34
- const dateMonth = dateMonth1 || dateMonth2 ;
15
+ $ ( "a.group" ) . each ( function ( ) {
16
+ let round : string = $ ( this ) . find ( "div:nth-child(1) > div:nth-child(1) > span:nth-child(1) > span:nth-child(1)" ) . text ( ) . trim ( ) ;
17
+ let date : string = $ ( this ) . find ( "div:nth-child(1) > div:nth-child(1) > span:nth-child(1) > span:nth-child(2)" ) . contents ( ) . get ( ) [ 1 ] ;
18
+ date = $ ( date ) . text ( ) ;
19
+
20
+ let eventTitle : string = $ ( this ) . find ( "div:nth-child(1) > div:nth-child(1) > span:nth-child(3)" ) . text ( ) . trim ( ) ;
21
+ let raceCountry : string = $ ( this ) . find ( "div:nth-child(1) > div:nth-child(1) > span:nth-child(2) > p:nth-child(2)" ) . text ( ) . trim ( ) ;
22
+
23
+ //Semantics differ for the next race
24
+ if ( round === "" ) {
25
+ round = $ ( this ) . find ( "div:nth-child(1) > div:nth-child(2) > span:nth-child(1) > span:nth-child(1)" ) . text ( ) . trim ( ) ;
26
+ }
27
+
28
+ //Yes four differ semantics
29
+ const dateGetPath : string [ ] = [
30
+ "div:nth-child(1) > div:nth-child(1) > span:nth-child(4)" ,
31
+ "div:nth-child(1) > div:nth-child(1) > div:nth-child(4) > span:nth-child(1)" ,
32
+ "div:nth-child(1) > div:nth-child(2) > div:nth-child(4) > span:nth-child(1)" ,
33
+ ] ;
34
+ let i = 0 ;
35
+ while ( date === "" ) {
36
+ date = $ ( this ) . find ( dateGetPath [ i ++ ] ) . text ( ) . trim ( ) ;
37
+ }
38
+
39
+ //Semantics differ for the next race
40
+ if ( eventTitle === "" ) eventTitle = $ ( this ) . find ( "div:nth-child(1) > div:nth-child(2) > span:nth-child(3)" ) . text ( ) . trim ( ) ;
41
+
42
+ //Semantics differ for the next race
43
+ if ( raceCountry === "" ) raceCountry = $ ( this ) . find ( "div:nth-child(1) > div:nth-child(2) > span:nth-child(2) > p:nth-child(2)" ) . text ( ) . trim ( ) ;
35
44
36
45
if ( round !== undefined && raceCountry !== undefined && eventTitle !== undefined ) {
37
46
const singleSchedule = {
38
47
round,
39
- date : dateDays . concat ( " ", dateMonth ) ,
48
+ date : date . replaceAll ( " ", "" ) ,
40
49
raceCountry,
41
50
eventTitle,
42
51
} ;
0 commit comments