|
const LIST_GOING_ONLY = true; |
|
// Change this to false if you'd like to see all events, instead of |
|
// just those that you've marked as Attending. |
|
|
|
function fixDate(dateTimeStr) { |
|
const dateTimeWithTimezone = `${dateTimeStr} UTC+0700`; |
|
const dateObj = new Date(dateTimeWithTimezone); |
|
if (isNaN(dateObj.getTime())) { |
|
return null; |
|
} |
|
return dateObj; |
|
} |
|
|
|
function createGoogleCalendarLink(event) { |
|
const baseUrl = 'https://www.google.com/calendar/event?action=TEMPLATE'; |
|
const start = new Date(event.start).toISOString().replace(/-|:|\.\d\d\d/g, ""); |
|
const end = new Date(event.end).toISOString().replace(/-|:|\.\d\d\d/g, ""); |
|
const title = encodeURIComponent(event.title); |
|
const location = encodeURIComponent(event.loc); |
|
const description = encodeURIComponent(event.desc.substring(0, 500)); |
|
const calendarUrl = `${baseUrl}&text=${title}&dates=${start}/${end}&details=${description}&location=${location}`; |
|
return calendarUrl; |
|
} |
|
|
|
async function grabSessions() { |
|
console.log('Grabbing sessions...'); |
|
let userAgenda = await fetch('https://whova.com/webapp/api/agenda/sessions/?event_id=dcbkk_202310'); |
|
let agendaDataJson = await userAgenda.json(); |
|
let agendaData = agendaDataJson?.result?.sessions; |
|
let sessions = agendaData.map( session => { |
|
return { |
|
going: (session.added === "yes"), |
|
id: session.id, |
|
title: session.title, |
|
loc: session.loc, |
|
start_ts: session.start_ts, |
|
start: fixDate(session.start_ts), |
|
end_ts: session.end_ts, |
|
end: fixDate(session.end_ts), |
|
desc: session.desc, |
|
} |
|
return null; |
|
}).filter(sesh => { return sesh != null }) |
|
return sessions.sort((a, b) => a.start - b.start); |
|
} |
|
|
|
function printLinks(sessions, options) { |
|
sessions.forEach(session => { |
|
if(options?.goingOnly && !session.going){ return; } |
|
console.log(`%c${session.start_ts} %c- ${session.loc}`, `font-weight: bold; color: #1a60ab`, `font-weight: inherit; color: default;`); |
|
console.log(`${session.title}`) |
|
console.log(createGoogleCalendarLink(session)) |
|
console.log('\n') |
|
}) |
|
} |
|
|
|
let sessions = await grabSessions(); |
|
printLinks( sessions, { goingOnly: LIST_GOING_ONLY }); |