From b71b9c3b1bc27d163565f00ffffc90c4bd1220f4 Mon Sep 17 00:00:00 2001 From: Rafa Date: Thu, 9 Jan 2025 13:09:55 +0100 Subject: [PATCH 01/14] feat: created --- lib/scrap/sprint/qualy.ts | 0 lib/scrap/sprint/race.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/scrap/sprint/qualy.ts create mode 100644 lib/scrap/sprint/race.ts diff --git a/lib/scrap/sprint/qualy.ts b/lib/scrap/sprint/qualy.ts new file mode 100644 index 0000000..e69de29 diff --git a/lib/scrap/sprint/race.ts b/lib/scrap/sprint/race.ts new file mode 100644 index 0000000..e69de29 From d3c004414b443d9914905d3d9cb761f42fd2bca5 Mon Sep 17 00:00:00 2001 From: Rafa Date: Fri, 10 Jan 2025 13:15:30 +0100 Subject: [PATCH 02/14] feat: add function to retrieve and process sprint race results from Formula 1 API --- lib/scrap/sprint/race.js | 148 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 lib/scrap/sprint/race.js diff --git a/lib/scrap/sprint/race.js b/lib/scrap/sprint/race.js new file mode 100644 index 0000000..ff514f4 --- /dev/null +++ b/lib/scrap/sprint/race.js @@ -0,0 +1,148 @@ +import { generateRaceId, formatDriver, formatTeam } from "../utils.js" + +export const getSprintRaceResults = async (year, race, page) => { + //const raceId = generateRaceId(race, year) + const raceId = "qatar_2024" + const raceNumber = 1251 // Refers to the race number of the grand prix, its the id of the f1 page + const url = `https://www.formula1.com/en/results/${year}/races/${raceNumber}/${race}/sprint-results` + + await page.goto(url) + + await page.waitForSelector( + 'table[class="f1-table f1-table-with-data w-full"]' + ) + + const results = await page.evaluate(() => { + const table = document.querySelector( + 'table[class="f1-table f1-table-with-data w-full"]' + ) + const rows = table?.querySelectorAll("tbody tr") + const data = [] + + rows?.forEach((row) => { + const columns = row.querySelectorAll("td p") + const position = columns[0]?.innerText.split("\n")[0].trim() || null + const driver = columns[2]?.innerText.trim().toLowerCase() || null + const team = columns[3]?.innerText.trim().toLowerCase() || null + const laps = columns[4]?.innerText.trim().toLowerCase() || null + const raceTime = columns[5]?.innerText.split("\n")[0].trim() || null + const points = columns[6]?.innerText.split("\n")[0].trim() || null + + data.push({ + position, + driver, + team, + laps, + raceTime, + points, + }) + }) + + return data + }) + + // now we need to get the sprint grid position + + const sprintUrl = `https://www.formula1.com/en/results/${year}/races/${raceNumber}/${race}/sprint-grid` + await page.goto(sprintUrl) + + await page.waitForSelector( + 'table[class="f1-table f1-table-with-data w-full"]' + ) + + const qualyResults = await page.evaluate(() => { + const table = document.querySelector( + 'table[class="f1-table f1-table-with-data w-full"]' + ) + const rows = table?.querySelectorAll("tbody tr") + const data = [] + + rows?.forEach((row) => { + const columns = row.querySelectorAll("td p") + const gridPosition = columns[0]?.innerText.split("\n")[0].trim() || null + const driver = columns[2]?.innerText.trim().toLowerCase() || null + + data.push({ + gridPosition, + driver, + }) + }) + + return data + }) + + const sprintQualyResults = qualyResults.map((result) => { + return { + driverId: formatDriver(result.driver), + gridPosition: result.gridPosition, + } + }) + + const formattedResults = results.map((result) => { + return { + Race_ID: raceId, + Driver_ID: formatDriver(result.driver), + Team_ID: formatTeam(result.team), + Finishing_Position: result.position, + laps: result.laps, + Race_Time: result.raceTime, + Points_Obtained: parseInt(result.points), // Asumiendo que los puntos siempre son numéricos y en el formato "X" + } + }) + + // now, with the sprint grid and the sprint race results, we can merge them in one + + const mergedResults = formattedResults.map((result) => { + // Find the matching sprint grid result for the driver + const sprintQualy = sprintQualyResults.find( + (qualy) => qualy.driverId === result.Driver_ID + ) + + // Return a new object with the merged data + return { + ...result, // Keep all existing properties + Grid_Position: sprintQualy?.gridPosition || null, // Add grid position if found, else null + } + }) + + console.log(mergedResults) + + // ;(async () => { + // const RaceResults = await formattedResults + // // Ensure the data is an array and has items before inserting + // if (Array.isArray(RaceResults) && RaceResults.length > 0) { + // for (const result of RaceResults) { + // try { + // await clientWriter.execute({ + // sql: `INSERT INTO Results (Driver_ID, Race_ID, Team_ID, Finishing_Position, Grid_Position, Race_Time, Points_Obtained) VALUES (:Driver_ID, :Race_ID, :Team_ID, :Finishing_Position, :Grid_Position, :Race_Time, :Points_Obtained)`, + // args: { + // Driver_ID: result.Driver_ID, + // Race_ID: raceId, + // Team_ID: result.Team_ID, + // Finishing_Position: result.Finishing_Position, + // Grid_Position: result.Grid_Position, + // Race_Time: result.Race_Time, + // Points_Obtained: result.Points_Obtained, + // }, + // }) + // } catch (error) { + // console.error("Error inserting race results:", error) + // } + // try { + // await clientWriter.execute({ + // sql: `UPDATE Races SET Winner_ID = :Winner_ID, Team_Winner_ID = :Team_Winner_ID WHERE Race_ID = :Race_ID`, + // args: { + // Winner_ID: formattedResults[0].Driver_ID, + // Team_Winner_ID: formattedResults[0].Team_ID, + // Race_ID: raceId, + // }, + // }) + // } catch (error) { + // console.error("Error updating races", error) + // } + // } + // } else { + // console.log("Error inserting data") + // } + // })() +} From 26beba750171e00377c2c798056e219b60c8c978 Mon Sep 17 00:00:00 2001 From: Rafa Date: Fri, 10 Jan 2025 13:15:41 +0100 Subject: [PATCH 03/14] feat: add sprint race data processing script to TypeScript configuration --- tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index c3b6da6..20c8ac8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,7 +28,8 @@ ".next/types/**/*.ts", "app/api/[year]/drivers/[driverId]/route.tsx", "middleware.js", - "app/i18n.js" + "app/i18n.js", + "lib/scrap/sprint/race.js" ], "exclude": ["node_modules"] } From e4eae47664b0dddb1a6e82b226f4a043f17af7e1 Mon Sep 17 00:00:00 2001 From: Rafa Date: Fri, 10 Jan 2025 13:15:50 +0100 Subject: [PATCH 04/14] renamed --- lib/scrap/sprint/race.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lib/scrap/sprint/race.ts diff --git a/lib/scrap/sprint/race.ts b/lib/scrap/sprint/race.ts deleted file mode 100644 index e69de29..0000000 From dbc44c57095a09a91ea1355dc33ddaae8ff79458 Mon Sep 17 00:00:00 2001 From: Rafa Date: Fri, 10 Jan 2025 13:15:55 +0100 Subject: [PATCH 05/14] feat: update race data retrieval to use sprint race results for Qatar 2024 --- lib/scrap/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/scrap/index.js b/lib/scrap/index.js index 403a615..2ecc54c 100644 --- a/lib/scrap/index.js +++ b/lib/scrap/index.js @@ -2,17 +2,19 @@ import { chromium } from "playwright" import { getRaceResults } from "./race.js" import { getQualyResults } from "./qualy.js" import { getPracticeResults } from "./fp.js" +import { getSprintRaceResults } from "./sprint/race.js" ;(async () => { const browser = await chromium.launch({ headless: false }) const context = await browser.newContext() const page = await context.newPage() const year = 2024 - const race = "abu-dhabi" + const race = "qatar" //await getPracticeResults(year, race, page) //await getQualyResults(year, race, page) - await getRaceResults(year, race, page) + await getSprintRaceResults(year, race, page) + //await getRaceResults(year, race, page) await context.close() await browser.close() From 024251a1cdbc8ad6080f11d2d99e8ce5c173739c Mon Sep 17 00:00:00 2001 From: Rafa Date: Fri, 10 Jan 2025 13:43:53 +0100 Subject: [PATCH 06/14] feat: add F1 grid data and enhance team formatting logic with driver integration --- lib/scrap/utils.js | 102 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/lib/scrap/utils.js b/lib/scrap/utils.js index bec4c78..985f25f 100644 --- a/lib/scrap/utils.js +++ b/lib/scrap/utils.js @@ -2,6 +2,90 @@ export const generateRaceId = (race, year) => { return `${race}_${year}` } +// object array with the info of the current grid of the f1, includes drivers and his teams +export const grid = [ + { + driver: "max_verstappen", + team: "red_bull", + }, + { + driver: "perez", + team: "red_bull", + }, + { + driver: "hamilton", + team: "mercedes", + }, + { + driver: "russell", + team: "mercedes", + }, + { + driver: "sainz", + team: "ferrari", + }, + { + driver: "leclerc", + team: "ferrari", + }, + { + driver: "norris", + team: "mclaren", + }, + { + driver: "piastri", + team: "mclaren", + }, + { + driver: "bottas", + team: "sauber", + }, + { + driver: "zhou", + team: "sauber", + }, + { + driver: "colapinto", + team: "williams", + }, + { + driver: "albon", + team: "williams", + }, + { + driver: "alonso", + team: "aston_martin", + }, + { + driver: "stroll", + team: "aston_martin", + }, + { + driver: "hulkenberg", + team: "haas", + }, + { + driver: "kevin_magnussen", + team: "haas", + }, + { + driver: "ocon", + team: "alpine", + }, + { + driver: "gasly", + team: "alpine", + }, + { + driver: "tsunoda", + team: "rb", + }, + { + driver: "lawson", + team: "rb", + }, +] + export const exceptions = ["max verstappen", "kevin magnussen"] export const teamExceptions = ["red bull", "aston martin"] @@ -19,9 +103,25 @@ export const formatDriver = (driver) => { } } -export const formatTeam = (team) => { +export const formatTeam = (team, driver = null) => { let teamId + // Find the driver in the grid array + if (driver) { + // Handle driver exceptions + const formattedDriver = exceptions.includes(driver) + ? driver.replace(" ", "_") + : driver + + // Find the driver in the grid array + const driverEntry = grid.find((entry) => entry.driver === formattedDriver) + + // If a matching driver is found, use their team; otherwise, proceed with normal logic + if (driverEntry) { + return (teamId = driverEntry.team) + } + } + // Default logic if driver is not provided or not found in the grid if (teamExceptions.includes(team)) { return (teamId = team.replace(" ", "_")) } else { From f068fd5187f860d84ed3d5e540760279d79e48f2 Mon Sep 17 00:00:00 2001 From: Rafa Date: Fri, 10 Jan 2025 13:43:58 +0100 Subject: [PATCH 07/14] feat: enhance sprint race results processing with improved team formatting and database integration --- lib/scrap/sprint/race.js | 64 ++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/lib/scrap/sprint/race.js b/lib/scrap/sprint/race.js index ff514f4..9ff71c7 100644 --- a/lib/scrap/sprint/race.js +++ b/lib/scrap/sprint/race.js @@ -1,3 +1,4 @@ +//import { db } from "@/db/index.js" import { generateRaceId, formatDriver, formatTeam } from "../utils.js" export const getSprintRaceResults = async (year, race, page) => { @@ -42,7 +43,6 @@ export const getSprintRaceResults = async (year, race, page) => { }) // now we need to get the sprint grid position - const sprintUrl = `https://www.formula1.com/en/results/${year}/races/${raceNumber}/${race}/sprint-grid` await page.goto(sprintUrl) @@ -82,7 +82,7 @@ export const getSprintRaceResults = async (year, race, page) => { return { Race_ID: raceId, Driver_ID: formatDriver(result.driver), - Team_ID: formatTeam(result.team), + Team_ID: formatTeam(result.team, result.driver), Finishing_Position: result.position, laps: result.laps, Race_Time: result.raceTime, @@ -106,43 +106,31 @@ export const getSprintRaceResults = async (year, race, page) => { }) console.log(mergedResults) - - // ;(async () => { - // const RaceResults = await formattedResults - // // Ensure the data is an array and has items before inserting - // if (Array.isArray(RaceResults) && RaceResults.length > 0) { - // for (const result of RaceResults) { - // try { - // await clientWriter.execute({ - // sql: `INSERT INTO Results (Driver_ID, Race_ID, Team_ID, Finishing_Position, Grid_Position, Race_Time, Points_Obtained) VALUES (:Driver_ID, :Race_ID, :Team_ID, :Finishing_Position, :Grid_Position, :Race_Time, :Points_Obtained)`, - // args: { - // Driver_ID: result.Driver_ID, - // Race_ID: raceId, - // Team_ID: result.Team_ID, - // Finishing_Position: result.Finishing_Position, - // Grid_Position: result.Grid_Position, - // Race_Time: result.Race_Time, - // Points_Obtained: result.Points_Obtained, - // }, + // ;async () => { + // const sprintRaceResults = await mergedResults + + // if (Array.isArray(sprintRaceResults) && sprintRaceResults.length > 0) { + // for (const result of sprintRaceResults) { + // try { + // await db + // .insert(Sprint_Race) + // .values({ + // Race_ID: raceId, + // Driver_ID: result.Driver_ID, + // Team_ID: result.Team_ID, + // Finishing_Position: result.Finishing_Position, + // laps: result.laps, + // Race_Time: result.Race_Time, + // Points_Obtained: result.Points_Obtained, + // Grid_Position: result.Grid_Position, // }) - // } catch (error) { - // console.error("Error inserting race results:", error) - // } - // try { - // await clientWriter.execute({ - // sql: `UPDATE Races SET Winner_ID = :Winner_ID, Team_Winner_ID = :Team_Winner_ID WHERE Race_ID = :Race_ID`, - // args: { - // Winner_ID: formattedResults[0].Driver_ID, - // Team_Winner_ID: formattedResults[0].Team_ID, - // Race_ID: raceId, - // }, - // }) - // } catch (error) { - // console.error("Error updating races", error) - // } + // .onConflictDoNothing() + + // console.log("Sprint Race inserted correctly") + // } catch (error) { + // console.error(error) // } - // } else { - // console.log("Error inserting data") // } - // })() + // } + // } } From 5d3589d09a004d727203421bd19f038232ea62b8 Mon Sep 17 00:00:00 2001 From: Rafa Date: Tue, 14 Jan 2025 17:18:59 +0100 Subject: [PATCH 08/14] feat: add qualifying race script to TypeScript configuration --- tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 20c8ac8..73d2128 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -29,7 +29,8 @@ "app/api/[year]/drivers/[driverId]/route.tsx", "middleware.js", "app/i18n.js", - "lib/scrap/sprint/race.js" + "lib/scrap/sprint/race.js", + "lib/scrap/sprint/qualy.js" ], "exclude": ["node_modules"] } From 72d9a4d3649a24b06c17a3120908b644bdfe1185 Mon Sep 17 00:00:00 2001 From: Rafa Date: Tue, 14 Jan 2025 17:19:04 +0100 Subject: [PATCH 09/14] feat: integrate sprint qualifying results retrieval into the scraping process --- lib/scrap/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/scrap/index.js b/lib/scrap/index.js index 2ecc54c..8d94b80 100644 --- a/lib/scrap/index.js +++ b/lib/scrap/index.js @@ -3,6 +3,7 @@ import { getRaceResults } from "./race.js" import { getQualyResults } from "./qualy.js" import { getPracticeResults } from "./fp.js" import { getSprintRaceResults } from "./sprint/race.js" +import { getSprintQualyResults } from "./sprint/qualy.js" ;(async () => { const browser = await chromium.launch({ headless: false }) const context = await browser.newContext() @@ -13,8 +14,9 @@ import { getSprintRaceResults } from "./sprint/race.js" //await getPracticeResults(year, race, page) //await getQualyResults(year, race, page) - await getSprintRaceResults(year, race, page) - //await getRaceResults(year, race, page) + //await getSprintQualyResults(year, race, page) + //await getSprintRaceResults(year, race, page) + await getRaceResults(year, race, page) await context.close() await browser.close() From de7c093abf043273121d80ee37813fd4f882e1a3 Mon Sep 17 00:00:00 2001 From: Rafa Date: Tue, 14 Jan 2025 17:19:08 +0100 Subject: [PATCH 10/14] feat: add fast lap and lap time retrieval to race results processing --- lib/scrap/race.js | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/scrap/race.js b/lib/scrap/race.js index c8cdb0a..57cef87 100644 --- a/lib/scrap/race.js +++ b/lib/scrap/race.js @@ -25,6 +25,15 @@ export const getRaceResults = async (year, race, page) => { const driver = columns[1]?.innerText.trim().toLowerCase() || null const team = columns[5]?.innerText.trim().toLowerCase() || null const gridPosition = columns[6]?.innerText.split("\n")[0].trim() || null + const fastLap = + columns[8] + ?.querySelector(`span[aria-hidden="true"]`) + ?.innerText.trim() || // Try `aria-hidden` + columns[8]?.querySelector(`span.visually-hidden`)?.innerText.trim() || // Fallback to `visually-hidden` + null + + const lapTime = fastLap ? fastLap.match(/\d+:\d+\.\d+/)?.[0] : null + const raceTime = columns[10] ?.querySelector(`span[aria-hidden="true"]`) @@ -39,6 +48,8 @@ export const getRaceResults = async (year, race, page) => { raceTime, points, gridPosition, + lapTime, + fastLap, }) }) @@ -53,11 +64,33 @@ export const getRaceResults = async (year, race, page) => { Finishing_Position: result.position, Grid_Position: result.gridPosition, Race_Time: result.raceTime, - Points_Obtained: parseInt(result.points), // Asumiendo que los puntos siempre son numéricos y en el formato "X" + Points_Obtained: parseInt(result.points), + fast_lap: result.lapTime, } }) + // we want to retrieve the fastest overall lap of the race + + const fastestLap = results.reduce( + (acc, result) => { + // Check if the lapTime exists and is a valid lap time + if (result.lapTime) { + const lapTime = result.lapTime + + // Compare lap time only if it's the fastest one + if (!acc.lapTime || lapTime < acc.lapTime) { + acc.lapTime = lapTime + acc.driverId = formatDriver(result.driver) + acc.teamId = formatTeam(result.team) + } + } + return acc + }, + { lapTime: null, driverId: null, teamId: null } + ) + console.log(formattedResults) + console.log(fastestLap) ;(async () => { const RaceResults = await formattedResults // Ensure the data is an array and has items before inserting @@ -81,9 +114,19 @@ export const getRaceResults = async (year, race, page) => { } try { await clientWriter.execute({ - sql: `UPDATE Races SET Winner_ID = :Winner_ID, Team_Winner_ID = :Team_Winner_ID WHERE Race_ID = :Race_ID`, + sql: `UPDATE Races + SET + Winner_ID = :Winner_ID, + fast_lap = :fast_lap, + fast_lap_driver_id = :fast_lap_driver_id, + fast_lap_team_id = :fast_lap_team_id, + Team_Winner_ID = :Team_Winner_ID + WHERE Race_ID = :Race_ID`, args: { Winner_ID: formattedResults[0].Driver_ID, + fast_lap: fastestLap.lapTime, + fast_lap_driver_id: fastestLap.driverId, + fast_lap_team_id: fastestLap.teamId, Team_Winner_ID: formattedResults[0].Team_ID, Race_ID: raceId, }, From 317dfd2bc859063e04e7754377ee38399b4a5ed6 Mon Sep 17 00:00:00 2001 From: Rafa Date: Tue, 14 Jan 2025 17:19:15 +0100 Subject: [PATCH 11/14] feat: add sprint qualifying results retrieval functionality --- lib/scrap/sprint/qualy.js | 85 +++++++++++++++++++++++++++++++++++++++ lib/scrap/sprint/qualy.ts | 0 2 files changed, 85 insertions(+) create mode 100644 lib/scrap/sprint/qualy.js delete mode 100644 lib/scrap/sprint/qualy.ts diff --git a/lib/scrap/sprint/qualy.js b/lib/scrap/sprint/qualy.js new file mode 100644 index 0000000..3e4cb22 --- /dev/null +++ b/lib/scrap/sprint/qualy.js @@ -0,0 +1,85 @@ +//import { db } from "@/db/index.js" +import { generateRaceId, formatDriver, formatTeam } from "../utils.js" + +export const getSprintQualyResults = async (year, race, page) => { + //const raceId = generateRaceId(race, year) + const raceId = "qatar_2024" + const raceNumber = 1251 // Refers to the race number of the grand prix, its the id of the f1 page + const url = `https://www.formula1.com/en/results/${year}/races/${raceNumber}/${race}/sprint-qualifying` + + await page.goto(url) + + await page.waitForSelector( + 'table[class="f1-table f1-table-with-data w-full"]' + ) + + const results = await page.evaluate(() => { + const table = document.querySelector( + 'table[class="f1-table f1-table-with-data w-full"]' + ) + const rows = table?.querySelectorAll("tbody tr") + const data = [] + + rows?.forEach((row) => { + const columns = row.querySelectorAll("td p") + const gridPosition = columns[0]?.innerText.split("\n")[0].trim() || null + const driver = columns[2]?.innerText.trim().toLowerCase() || null + const team = columns[3]?.innerText.trim().toLowerCase() || null + const sq1 = columns[4]?.innerText.split("\n")[0].trim() || null + const sq2 = columns[5]?.innerText.split("\n")[0].trim() || null + const sq3 = columns[6]?.innerText.split("\n")[0].trim() || null + + data.push({ + gridPosition, + driver, + team, + sq1, + sq2, + sq3, + }) + }) + + return data + }) + + const formattedResults = results.map((result) => { + return { + Race_ID: raceId, + Driver_ID: formatDriver(result.driver), + Team_ID: formatTeam(result.team, result.driver), + Grid_Position: result.gridPosition, + SQ1: result.sq1, + SQ2: result.sq2, + SQ3: result.sq3, + } + }) + + console.log(formattedResults) + // ;async () => { + // const sprintRaceResults = await mergedResults + + // if (Array.isArray(sprintRaceResults) && sprintRaceResults.length > 0) { + // for (const result of sprintRaceResults) { + // try { + // await db + // .insert(Sprint_Race) + // .values({ + // Race_ID: raceId, + // Driver_ID: result.Driver_ID, + // Team_ID: result.Team_ID, + // Finishing_Position: result.Finishing_Position, + // laps: result.laps, + // Race_Time: result.Race_Time, + // Points_Obtained: result.Points_Obtained, + // Grid_Position: result.Grid_Position, + // }) + // .onConflictDoNothing() + + // console.log("Sprint Race inserted correctly") + // } catch (error) { + // console.error(error) + // } + // } + // } + // } +} diff --git a/lib/scrap/sprint/qualy.ts b/lib/scrap/sprint/qualy.ts deleted file mode 100644 index e69de29..0000000 From b99621490c0f969a8936c22e0fce4668179b39b4 Mon Sep 17 00:00:00 2001 From: Rafa Date: Tue, 14 Jan 2025 17:19:22 +0100 Subject: [PATCH 12/14] feat: update sprint race standings to include new points calculation --- lib/scrap/sprint/race.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/scrap/sprint/race.js b/lib/scrap/sprint/race.js index 9ff71c7..c70ca11 100644 --- a/lib/scrap/sprint/race.js +++ b/lib/scrap/sprint/race.js @@ -126,6 +126,8 @@ export const getSprintRaceResults = async (year, race, page) => { // }) // .onConflictDoNothing() + // also, we need to update the standings with the new points + // console.log("Sprint Race inserted correctly") // } catch (error) { // console.error(error) From e49cb41e8002d45d018f8067f0481a7b0717d124 Mon Sep 17 00:00:00 2001 From: Rafa Date: Tue, 14 Jan 2025 17:30:05 +0100 Subject: [PATCH 13/14] feat: enhance button components with TypeScript props and className support --- components/buttons/BackBtn.tsx | 6 +++++- components/buttons/CopyBtn.tsx | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/components/buttons/BackBtn.tsx b/components/buttons/BackBtn.tsx index fcee08d..6c96cfa 100644 --- a/components/buttons/BackBtn.tsx +++ b/components/buttons/BackBtn.tsx @@ -2,7 +2,11 @@ import Link from "next/link" import initTranslations from "@/app/i18n" import { buttonVariants } from "@/components/ui/button" -export async function BackBtn({ locale }: { locale: string }) { +interface BackBtnProps extends React.HTMLAttributes { + locale: string +} + +export async function BackBtn({ locale }: BackBtnProps) { const { t } = await initTranslations(locale, ["common"]) return ( diff --git a/components/buttons/CopyBtn.tsx b/components/buttons/CopyBtn.tsx index 97e75ff..6a767d7 100644 --- a/components/buttons/CopyBtn.tsx +++ b/components/buttons/CopyBtn.tsx @@ -2,14 +2,15 @@ import { Button } from "@/components/ui/button" import { Check, Copy } from "lucide-react" -import { copyUrlToClipboard } from "@/lib/utils" +import { cn, copyUrlToClipboard } from "@/lib/utils" import { useState } from "react" interface CopyBtnProps extends React.HTMLAttributes { text: string + className?: string } -export default function CopyBtn({ text }: CopyBtnProps) { +export default function CopyBtn({ text, className }: CopyBtnProps) { const [copied, setCopied] = useState(false) const handleCopy = async () => { @@ -23,7 +24,10 @@ export default function CopyBtn({ text }: CopyBtnProps) { } return ( - From ca0578ad7fa6d615efd4563955097e0a410901c0 Mon Sep 17 00:00:00 2001 From: Rafa Date: Tue, 14 Jan 2025 17:30:08 +0100 Subject: [PATCH 14/14] feat: comment out race results retrieval in scraping process --- lib/scrap/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/scrap/index.js b/lib/scrap/index.js index 8d94b80..f973902 100644 --- a/lib/scrap/index.js +++ b/lib/scrap/index.js @@ -16,7 +16,7 @@ import { getSprintQualyResults } from "./sprint/qualy.js" //await getQualyResults(year, race, page) //await getSprintQualyResults(year, race, page) //await getSprintRaceResults(year, race, page) - await getRaceResults(year, race, page) + //await getRaceResults(year, race, page) await context.close() await browser.close()