@@ -8,29 +8,43 @@ import { isTeam } from "../types/types";
8
8
export const getTeamLineup = async ( ) : Promise < isTeam [ ] > => {
9
9
try {
10
10
let teams : isTeam [ ] = [ ] ;
11
-
12
11
const response = await axios ( staticLinks . teams ) ;
13
12
const $ = cheerio . load ( response . data ) ;
14
13
15
- $ ( "a.group" ) . each ( function ( ) {
16
- const name : string = $ ( this ) . find ( "div > div:nth-child(3) > div:nth-child(1) > span:nth-child(1)" ) . text ( ) ;
17
- const driver1_0 : string = $ ( this ) . find ( "div > div:nth-child(5) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > p:nth-child(1)" ) . text ( ) ;
18
- const driver1_1 : string = $ ( this ) . find ( "div > div:nth-child(5) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > p:nth-child(2)" ) . text ( ) ;
19
- const driver2_0 : string = $ ( this ) . find ( "div > div:nth-child(5) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > p:nth-child(1)" ) . text ( ) ;
20
- const driver2_1 : string = $ ( this ) . find ( "div > div:nth-child(5) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > p:nth-child(2)" ) . text ( ) ;
14
+ async function getTeamPoints ( ) : Promise < Array < [ string , number ] > > {
15
+ const response = await axios ( staticLinks . teamsPoints ) ;
16
+ const $ = cheerio . load ( response . data ) ;
17
+
18
+ const teamPoints : Array < [ string , number ] > = [ ] ;
19
+ $ ( ".f1-table tbody tr" ) . each ( function ( ) {
20
+ const teamName = $ ( this ) . find ( "td:nth-child(2)" ) . text ( ) . trim ( ) ;
21
+ const points = $ ( this ) . find ( "td:nth-child(3)" ) . text ( ) . trim ( ) ;
22
+ teamPoints . push ( [ teamName , Number ( points ) ] ) ;
23
+ } ) ;
24
+ return teamPoints ;
25
+ }
26
+ const teamsPoints = await getTeamPoints ( ) ;
27
+
28
+ $ ( 'a[data-f1rd-a7s-click="team_card_click"]' ) . each ( function ( ) {
29
+ const name : string = $ ( this ) . find ( "span:nth-child(3) > span > span:nth-child(1) > p" ) . text ( ) . trim ( ) ;
30
+ const driver1_0 : string = $ ( this ) . find ( "span:nth-child(3) > span > span:nth-child(1) > span > span:nth-child(1) > span:nth-child(2) > span:nth-child(1)" ) . text ( ) . trim ( ) ;
31
+ const driver1_1 : string = $ ( this ) . find ( "span:nth-child(3) > span > span:nth-child(1) > span > span:nth-child(1) > span:nth-child(2) > span:nth-child(2)" ) . text ( ) . trim ( ) ;
32
+ const driver2_0 : string = $ ( this ) . find ( "span:nth-child(3) > span > span:nth-child(1) > span > span:nth-child(2) > span:nth-child(2) > span:nth-child(1)" ) . text ( ) . trim ( ) ;
33
+ const driver2_1 : string = $ ( this ) . find ( "span:nth-child(3) > span > span:nth-child(1) > span > span:nth-child(2) > span:nth-child(2) > span:nth-child(2)" ) . text ( ) . trim ( ) ;
21
34
const driver1 = driver1_0 . concat ( " " , driver1_1 ) ;
22
35
const driver2 = driver2_0 . concat ( " " , driver2_1 ) ;
23
36
const drivers : string [ ] = [ driver1 , driver2 ] ;
24
37
25
- const carLogo : string | undefined = $ ( this ) . find ( "div > div :nth-child(3) > img :nth-child(2)" ) . attr ( "src" ) ;
26
- const carImage : string | undefined = $ ( this ) . find ( "div > div :nth-child(6 ) > img :nth-child(1) " ) . attr ( "src" ) ;
38
+ const carLogo : string | undefined = $ ( this ) . find ( "span :nth-child(3) > span > span :nth-child(2) > img " ) . attr ( "src" ) ;
39
+ const carImage : string | undefined = $ ( this ) . find ( "span :nth-child(3 ) > span :nth-child(2) > img " ) . attr ( "src" ) ;
27
40
28
- const points : string | undefined = $ ( this ) . find ( "div> div:nth-child(1) > div:nth-child(2) > p:nth-child(1)" ) . text ( ) ;
41
+ const foundedPoints = teamsPoints . find ( ( teamPoints ) => teamPoints [ 0 ] === name ) ;
42
+ const points : number | undefined = foundedPoints ? foundedPoints [ 1 ] : 0 ;
29
43
30
44
if ( name . length !== 0 ) {
31
45
const team : isTeam = {
32
46
name,
33
- points : parseInt ( points ) ,
47
+ points,
34
48
drivers,
35
49
carLogo,
36
50
carImage,
0 commit comments