Skip to content

Commit 1d1b92f

Browse files
committed
feat: fetch next year events
1 parent 0f16955 commit 1d1b92f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/scripts/events-import.ts

Lines changed: 10 additions & 1 deletion
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)

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

Lines changed: 4 additions & 5 deletions
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)