Skip to content

Commit

Permalink
Merge pull request #14182 from ethereum/events-fetching
Browse files Browse the repository at this point in the history
feat: fetch next year events
  • Loading branch information
corwintines authored Nov 28, 2024
2 parents 72c2e1f + f24ec0b commit d240e31
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
21 changes: 18 additions & 3 deletions src/scripts/events-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -39,15 +48,21 @@ 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 (
URL.canParse(imported.href) &&
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
}
Expand Down
9 changes: 4 additions & 5 deletions src/scripts/events/ethereum-events-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function getPageMetadata(url: string): Promise<Record<string, string>> {
}
}

export async function EthereumEventsImport() {
export async function EthereumEventsImport(year: number) {
const googleApiKey = process.env.GOOGLE_API_KEY
const sheetId = "1NEu_FCc1hnGAuRgPmbXXpf0h2lCrCOlMKbbFEqgkVDQ"

Expand All @@ -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()

Expand All @@ -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])
Expand Down

0 comments on commit d240e31

Please sign in to comment.