Skip to content

Commit d240e31

Browse files
authored
Merge pull request #14182 from ethereum/events-fetching
feat: fetch next year events
2 parents 72c2e1f + f24ec0b commit d240e31

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/scripts/events-import.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@ import "dotenv/config"
1212
const communityEvents = localEvents as CommunityConference[]
1313

1414
console.log("Community Events Import..")
15-
const ethereumEvents = await EthereumEventsImport()
15+
const year = new Date().getFullYear()
16+
const ethereumEvents = await EthereumEventsImport(year)
1617
// Can add multiple event sources here in the future
1718

19+
// Try to fetch next year too, if page available
20+
try {
21+
const eventsNextYear = await EthereumEventsImport(year + 1)
22+
ethereumEvents.push(...eventsNextYear)
23+
} catch (error: unknown) {
24+
console.error((error as Error).message)
25+
}
26+
1827
ethereumEvents.forEach((imported) => {
1928
const id = communityEvents.findIndex((local) =>
2029
tryMatchEvent(imported, local)
@@ -39,15 +48,21 @@ function tryMatchEvent(
3948
imported: CommunityConference,
4049
local: CommunityConference
4150
) {
42-
if (imported.title.toLocaleLowerCase() === local.title.toLocaleLowerCase())
51+
if (
52+
imported.title.toLocaleLowerCase() === local.title.toLocaleLowerCase() &&
53+
local.startDate === imported.startDate &&
54+
local.endDate === imported.endDate
55+
)
4356
return true
4457

4558
if (
4659
URL.canParse(imported.href) &&
4760
URL.canParse(local.href) &&
4861
new URL(imported.href).hostname.replace("www.", "") ===
4962
new URL(local.href).hostname.replace("www.", "") &&
50-
new URL(imported.href).pathname === new URL(local.href).pathname
63+
new URL(imported.href).pathname === new URL(local.href).pathname &&
64+
local.startDate === imported.startDate &&
65+
local.endDate === imported.endDate
5166
) {
5267
return true
5368
}

src/scripts/events/ethereum-events-import.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function getPageMetadata(url: string): Promise<Record<string, string>> {
2929
}
3030
}
3131

32-
export async function EthereumEventsImport() {
32+
export async function EthereumEventsImport(year: number) {
3333
const googleApiKey = process.env.GOOGLE_API_KEY
3434
const sheetId = "1NEu_FCc1hnGAuRgPmbXXpf0h2lCrCOlMKbbFEqgkVDQ"
3535

@@ -39,9 +39,8 @@ export async function EthereumEventsImport() {
3939
}
4040

4141
console.log("Importing Ethereum Events from Google Sheet")
42-
const currentYear = new Date().getFullYear()
4342
const res = await fetch(
44-
`https://sheets.googleapis.com/v4/spreadsheets/${sheetId}/values/${currentYear}%20Ethereum%20Events!B:H?majorDimension=COLUMNS&key=${googleApiKey}`
43+
`https://sheets.googleapis.com/v4/spreadsheets/${sheetId}/values/${year}%20Ethereum%20Events!B:H?majorDimension=COLUMNS&key=${googleApiKey}`
4544
)
4645
const data = await res.json()
4746

@@ -67,8 +66,8 @@ export async function EthereumEventsImport() {
6766

6867
let start, end
6968
try {
70-
start = Date.parse(`${startDate}, ${currentYear} GMT`)
71-
end = Date.parse(`${endDate}, ${currentYear} GMT`)
69+
start = Date.parse(`${startDate}, ${year} GMT`)
70+
end = Date.parse(`${endDate}, ${year} GMT`)
7271
if (Number.isNaN(start) || Number.isNaN(end)) continue
7372
} catch (e) {
7473
console.log("Invalid date", i[0])

0 commit comments

Comments
 (0)