diff --git a/src/scripts/events-import.ts b/src/scripts/events-import.ts index ec9ba8cbbc9..597556c7d0c 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) @@ -39,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 ( @@ -47,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 } 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])