File tree Expand file tree Collapse file tree 4 files changed +59
-10
lines changed Expand file tree Collapse file tree 4 files changed +59
-10
lines changed Original file line number Diff line number Diff line change 1
1
# F1 API
2
2
3
- The following scraper scrapes this given [ website ] ( https://www.formula1.com/en.html )
3
+ The scraper scrapes this given https://www.formula1.com/
4
4
5
5
## Functions added
6
6
@@ -11,4 +11,10 @@ The following scraper scrapes this given [website](https://www.formula1.com/en.h
11
11
Fetch the current list of F1 teams along with their information
12
12
13
13
- getDriverStandings
14
- Fetch F1 driver standings from points table
14
+ Fetch F1 driver standings from points table
15
+
16
+ - getConstructorStandings
17
+ Fetch Constructors standings from points table
18
+
19
+ - getWorldChampions
20
+ Fetch all the world champions
Original file line number Diff line number Diff line change 1
1
interface staticLinks {
2
2
drivers : string
3
3
teams : string
4
+ hallOfFame : string
4
5
}
5
6
6
7
interface dynamicLinks {
@@ -13,6 +14,7 @@ interface dynamicLinks {
13
14
export const staticLinks : staticLinks = {
14
15
drivers : "https://www.formula1.com/en/drivers.html" ,
15
16
teams : "https://www.formula1.com/en/teams.html" ,
17
+ hallOfFame : "https://www.formula1.com/en/drivers/hall-of-fame.html"
16
18
}
17
19
18
20
export const dynamicLinks : dynamicLinks = {
Original file line number Diff line number Diff line change
1
+ import axios from "axios"
2
+ import cheerio from "cheerio"
3
+
4
+ import { staticLinks } from "../endpoints/endpoints"
5
+
6
+ type hallOfFame = {
7
+ name : string
8
+ years : number [ ]
9
+ }
10
+
11
+ export const getWorldChampions = ( ) : Promise < hallOfFame [ ] > => {
12
+ let worldChampions : any = [ ]
13
+
14
+ return new Promise ( ( resolve , reject ) => {
15
+ axios ( staticLinks . hallOfFame )
16
+ . then ( response => {
17
+ const html = response . data
18
+ const $ = cheerio . load ( html )
19
+
20
+ $ ( 'article' ) . each (
21
+ function ( ) {
22
+ const years : number [ ] = [ ]
23
+
24
+ const name : string = $ ( this ) . find ( 'section > h4' ) . text ( ) . trim ( ) . split ( '-' ) [ 0 ]
25
+ $ ( this ) . find ( 'section > h4' ) . text ( ) . trim ( ) . split ( '-' ) [ 1 ]
26
+ . split ( ',' ) . forEach ( x => {
27
+ if ( x ) {
28
+ const year : number = parseInt ( x )
29
+ years . push ( year )
30
+ }
31
+ } )
32
+
33
+ if ( name . length !== 0 && years . length !== 0 ) {
34
+ const worldChampion : hallOfFame = {
35
+ name,
36
+ years
37
+ }
38
+ worldChampions . push ( worldChampion )
39
+ }
40
+ }
41
+ )
42
+ resolve ( worldChampions )
43
+ } )
44
+ . catch ( err => { reject ( err ) } )
45
+ } )
46
+ }
Original file line number Diff line number Diff line change @@ -2,17 +2,12 @@ import { getDriverData } from "./scraper/driver-data";
2
2
import { getTeamsData } from "./scraper/team-data" ;
3
3
import { getDriverStandings } from "./scraper/driver-standings" ;
4
4
import { getConstructorStandings } from './scraper/constructors-standings' ;
5
-
6
- const printDriverData = async ( ) : Promise < void > => {
7
- const f1Drivers = await getConstructorStandings ( 2003 )
8
- console . log ( f1Drivers )
9
- }
10
-
11
- printDriverData ( )
5
+ import { getWorldChampions } from './scraper/world-champions'
12
6
13
7
export {
14
8
getDriverData ,
15
9
getTeamsData ,
16
10
getDriverStandings ,
17
- getConstructorStandings
11
+ getConstructorStandings ,
12
+ getWorldChampions
18
13
}
You can’t perform that action at this time.
0 commit comments