Skip to content

Commit 880c030

Browse files
committed
Fix getRaceResults method
1 parent 827b689 commit 880c030

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/scraper/fastest-laps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const getFastestLaps = async (year: number = new Date().getFullYear()): P
1414
console.log(`${dynamicLinks.rootLink}/${year}/${dynamicLinks.fastestLap}`);
1515

1616
$(".f1-table > tbody:nth-child(2) > tr").each(function () {
17-
const grandPrixAll: Text = $(this).find("td:nth-child(1) > p:nth-child(1) > a").contents().get()[1];
17+
const grandPrixAll: string = $(this).find("td:nth-child(1) > p:nth-child(1) > a").contents().get()[1];
1818
const grandPrix: string = $(grandPrixAll).text();
1919
const driverName: string = $(this).find("td:nth-child(2) > p:nth-child(1) > span:nth-child(1)").text().trim();
2020
const car: string = $(this).find("td:nth-child(3) > p:nth-child(1)").text().trim();

src/scraper/race-results.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ export const getRaceResults = async (year: number = new Date().getFullYear()): P
1313
const $ = cheerio.load(response.data);
1414

1515
$(".f1-table > tbody:nth-child(2) > tr").each(function () {
16-
const grandPrix: string = $(this).find("td:nth-child(1) > p:nth-child(1) > a:nth-child(1)").text().trim();
16+
const grandPrixAll: string = $(this).find("td:nth-child(1) > p:nth-child(1) > a:nth-child(1)").contents().get()[1];
1717
const raceDate: string = $(this).find("td:nth-child(2) > p:nth-child(1)").text().trim();
18-
const driverFirstName: string = $(this).find("td:nth-child(3) > p:nth-child(1) > span:nth-child(1)").text().trim();
19-
const driverLastName: string = $(this).find("td:nth-child(3) > p:nth-child(1) > span:nth-child(2)").text().trim();
20-
const winner: string = driverFirstName.concat(" ", driverLastName);
18+
const driverName: string = $(this).find("td:nth-child(3) > p:nth-child(1) > span:nth-child(1)").text().trim();
19+
const winner: string = driverName.slice(0, driverName.length - 3);
2120
const car: string = $(this).find("td:nth-child(4) > p:nth-child(1)").text().trim();
2221
const laps: number = parseInt($(this).find("td:nth-child(5) > p:nth-child(1)").text().trim());
2322
const time: string = $(this).find("td:nth-child(6) > p:nth-child(1)").text().trim();
2423

24+
const date = new Date(Date.parse(`${raceDate} ${year}`));
25+
const grandPrix = $(grandPrixAll).text();
2526
if ((grandPrix.length !== 0 && raceDate.length !== 0 && winner.length !== 0, car.length !== 0, !Number.isNaN(laps), time.length !== 0)) {
2627
const raceResult: isRaceResult = {
2728
grandPrix,
28-
date: new Date(raceDate),
29+
date,
2930
winner,
3031
car,
3132
laps,

src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ export { getTeamLineup } from "./scraper/team-lineup";
44
export { getDriverStandings } from "./scraper/driver-standings";
55
export { getConstructorStandings } from "./scraper/constructors-standings";
66
export { getWorldChampions } from "./scraper/world-champions";
7-
// export { getRaceResults } from "./scraper/race-results";
7+
export { getRaceResults } from "./scraper/race-results";
88
// export { getRaceSchedule } from "./scraper/race-schedule";

0 commit comments

Comments
 (0)