Skip to content

Instantly share code, notes, and snippets.

@maxthoursie
Created March 20, 2018 10:37
Show Gist options
  • Save maxthoursie/48fb4f2cfa9df28ffc2b6cc6c52aed69 to your computer and use it in GitHub Desktop.
Save maxthoursie/48fb4f2cfa9df28ffc2b6cc6c52aed69 to your computer and use it in GitHub Desktop.
Script wayv business to page through the calendar view and save all events displayed as csv
function format_value(value) {
if (value instanceof Date) {
// Convert to google sheets compatible date string
return value.toISOString().substring(0, 16).replace("T", " ").replace(":", ".")
}
return value;
}
function to_csv(columns, rows) {
const sep = ";";
let csv = "";
csv += columns.join(sep) + "\n"
csv += rows.map(r=>columns.map(c=>format_value(r[c])).join(sep)).join("\n");
return csv;
}
function waitForLoading(cb) {
const loading = Session.get("loadingMessage");
if (!loading) {
setTimeout(cb, 100);
} else {
setTimeout(()=>waitForLoading(cb), 100);
}
}
function dumpDates(end, events, cb) {
if (myCal.fullCalendar("getDate") >= end) return cb(events);
setTimeout(()=>waitForLoading(()=>{
const e = Session.get("events");
if (e.length === 0) {
console.log("Warning: got 0 events for: ", myCal.fullCalendar("getDate"));
}
console.log("Got ", e.sort((a,b)=>a.start-b.start), " events for", myCal.fullCalendar("getDate"));
myCal.fullCalendar("next");
dumpDates(end, events.concat(e), cb);
}), 1000); // Wait for loading events.
}
//changeCalendarView(new Date("2018-01-01"), "resourceDay")
changeCalendarView(new Date("2017-01-01"), "agendaWeek")
dumpDates(new Date("2018-01-01T00:00:00+02:00"), [], (events) => {
console.log("Got ", events.length, " events")
//console.log(events);
//console.log(to_csv(["title", "start", "end", "resourceId"], Session.get("events")))
csv = to_csv(["title", "start", "end", "resourceId", "_id"], events);
})
// When done, at the console, do `copy(csv)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment