From 1d1b92f000f71b892c5174a387dcc8bad7a0c8d8 Mon Sep 17 00:00:00 2001 From: Paul Wackerow <54227730+wackerow@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:57:28 -0700 Subject: [PATCH 1/2] feat: fetch next year events --- src/scripts/events-import.ts | 11 ++++++++++- src/scripts/events/ethereum-events-import.ts | 9 ++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/scripts/events-import.ts b/src/scripts/events-import.ts index ec9ba8cbbc9..835138ff54e 100644 --- a/src/scripts/events-import.ts +++ b/src/scripts/events-import.ts @@ -12,9 +12,18 @@ import "dotenv/config" const communityEvents = localEvents as CommunityConference[] console.log("Community Events Import..") - const ethereumEvents = await EthereumEventsImport() + const year = new Date().getFullYear() + const ethereumEvents = await EthereumEventsImport(year) // Can add multiple event sources here in the future + // Try to fetch next year too, if page available + try { + const eventsNextYear = await EthereumEventsImport(year + 1) + ethereumEvents.push(...eventsNextYear) + } catch (error: unknown) { + console.error((error as Error).message) + } + ethereumEvents.forEach((imported) => { const id = communityEvents.findIndex((local) => tryMatchEvent(imported, local) diff --git a/src/scripts/events/ethereum-events-import.ts b/src/scripts/events/ethereum-events-import.ts index c1ad2cec5e5..b9c240b47b3 100644 --- a/src/scripts/events/ethereum-events-import.ts +++ b/src/scripts/events/ethereum-events-import.ts @@ -29,7 +29,7 @@ async function getPageMetadata(url: string): Promise> { } } -export async function EthereumEventsImport() { +export async function EthereumEventsImport(year: number) { const googleApiKey = process.env.GOOGLE_API_KEY const sheetId = "1NEu_FCc1hnGAuRgPmbXXpf0h2lCrCOlMKbbFEqgkVDQ" @@ -39,9 +39,8 @@ export async function EthereumEventsImport() { } console.log("Importing Ethereum Events from Google Sheet") - const currentYear = new Date().getFullYear() const res = await fetch( - `https://sheets.googleapis.com/v4/spreadsheets/${sheetId}/values/${currentYear}%20Ethereum%20Events!B:H?majorDimension=COLUMNS&key=${googleApiKey}` + `https://sheets.googleapis.com/v4/spreadsheets/${sheetId}/values/${year}%20Ethereum%20Events!B:H?majorDimension=COLUMNS&key=${googleApiKey}` ) const data = await res.json() @@ -67,8 +66,8 @@ export async function EthereumEventsImport() { let start, end try { - start = Date.parse(`${startDate}, ${currentYear} GMT`) - end = Date.parse(`${endDate}, ${currentYear} GMT`) + start = Date.parse(`${startDate}, ${year} GMT`) + end = Date.parse(`${endDate}, ${year} GMT`) if (Number.isNaN(start) || Number.isNaN(end)) continue } catch (e) { console.log("Invalid date", i[0]) From f24ec0b8b547ec9cf599e9bb3c1e270c182e990d Mon Sep 17 00:00:00 2001 From: Corwin Smith Date: Thu, 28 Nov 2024 09:43:26 -0700 Subject: [PATCH 2/2] add logic for tryMatchEvent to accomodate years --- src/scripts/events-import.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/scripts/events-import.ts b/src/scripts/events-import.ts index 835138ff54e..597556c7d0c 100644 --- a/src/scripts/events-import.ts +++ b/src/scripts/events-import.ts @@ -48,7 +48,11 @@ function tryMatchEvent( imported: CommunityConference, local: CommunityConference ) { - if (imported.title.toLocaleLowerCase() === local.title.toLocaleLowerCase()) + if ( + imported.title.toLocaleLowerCase() === local.title.toLocaleLowerCase() && + local.startDate === imported.startDate && + local.endDate === imported.endDate + ) return true if ( @@ -56,7 +60,9 @@ function tryMatchEvent( URL.canParse(local.href) && new URL(imported.href).hostname.replace("www.", "") === new URL(local.href).hostname.replace("www.", "") && - new URL(imported.href).pathname === new URL(local.href).pathname + new URL(imported.href).pathname === new URL(local.href).pathname && + local.startDate === imported.startDate && + local.endDate === imported.endDate ) { return true }