Created
June 29, 2022 15:09
-
-
Save 128f/cc824317ea4d34b72daa4895853125a3 to your computer and use it in GitHub Desktop.
A script to generate an ics file for AX2022
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const allEvents = $$('.event'); | |
function sanitizeTime(timeString) { | |
return timeString.split(/([0-9:]*)(AM|PM)/) | |
.filter(e => !!e) | |
.join(" ") | |
} | |
const events = allEvents.map((event) => { | |
try { | |
return { | |
date: event.querySelector(".date").textContent, | |
title: event.querySelector(".title").textContent, | |
startTime: sanitizeTime(event.querySelector(".timebar .start span").textContent), | |
endTime: sanitizeTime(event.querySelector(".timebar .end span").textContent), | |
location: event.querySelector(".timebar .channel span").textContent, | |
description: event.querySelector(".desc").textContent, | |
}; | |
} catch (e) { | |
console.log("error ", e); | |
} | |
}) | |
function calendarTimeFormat(date) { | |
const year = Intl.DateTimeFormat('en', { year: 'numeric', timeZone: 'utc' }).format(date); | |
const month = Intl.DateTimeFormat('en', { month: '2-digit', timeZone: 'utc' }).format(date); | |
const day = Intl.DateTimeFormat('en', { day: '2-digit', timeZone: 'utc' }).format(date); | |
const hour = Intl.DateTimeFormat('en', { hour: '2-digit', timeZone: 'utc', hour12: false }).format(date).split(' ')[0]; | |
const minute = Intl.DateTimeFormat('en', { minute: '2-digit', timeZone: 'utc' }).format(date).split(' ')[0]; | |
return year + month + day + "T" + hour + minute + "00Z"; | |
} | |
function calendarBlockFormat(event) { | |
// Date.parse("July 4, 2021 3:30 AM") | |
const startTime = Date.parse(`${event.date} ${event.startTime}`) | |
const endTime = Date.parse(`${event.date} ${event.endTime}`) | |
console.log(event); | |
console.log(startTime); | |
console.log(endTime); | |
return `BEGIN:VEVENT | |
DTSTART:${calendarTimeFormat(startTime)} | |
DTEND:${calendarTimeFormat(endTime)} | |
DTSTAMP:20220629T031830Z | |
DESCRIPTION:${event.description} | |
LAST-MODIFIED:20220629T031748Z | |
LOCATION:${event.location} | |
SUMMARY:${event.title} | |
END:VEVENT | |
` | |
} | |
const vevents = events.reduce((acc, event) => { | |
return acc + calendarBlockFormat(event); | |
}, ''); | |
const CAL_HEADER = ` | |
BEGIN:VCALENDAR | |
PRODID:-//Google Inc//Google Calendar 70.9054//EN | |
VERSION:2.0 | |
CALSCALE:GREGORIAN | |
METHOD:PUBLISH | |
X-WR-CALNAME:Anime Expo 2022 Schedule | |
X-WR-TIMEZONE:America/Los_Angeles | |
X-WR-CALDESC:Generated | |
` | |
const CAL_FOOTER = ` | |
END:VCALENDAR | |
` | |
CAL_HEADER + vevents + CAL_FOOTER; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I couldn't find a calendar file and wanted to plan my trip.
Steps: