Skip to content

Instantly share code, notes, and snippets.

@mondaychen
Forked from rsalzer/RandomWikimediaPicture.js
Last active November 16, 2020 14:40
Show Gist options
  • Save mondaychen/f12046211acd2f1d6f30c28ceead40da to your computer and use it in GitHub Desktop.
Save mondaychen/f12046211acd2f1d6f30c28ceead40da to your computer and use it in GitHub Desktop.
Scriptable-Script to open zoom link for my daughter
function runScriptable() {
const [title, link] = getZoomInfo(new Date());
const widget = createWidget(title, null, link);
if (config.runsInWidget) {
Script.setWidget(widget);
Script.complete();
} else {
widget.presentSmall();
}
}
runScriptable();
function getSpecialClassRotation(date) {
const SPECIAL_ROTATION = [
"ART",
"Library",
"Science",
"Music",
"PE",
"Science",
];
const ROTATION_OFFSET = 0;
const d = new Date(
Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())
);
// Set to nearest Thursday: current date + 4 - current day number
// Make Sunday's day number 7
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
// Calculate full weeks to nearest Thursday
const weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
// find position in rotation
return SPECIAL_ROTATION[(weekNo - ROTATION_OFFSET) % SPECIAL_ROTATION.length];
}
// console.log(getSpecialClassRotation(new Date()));
function getZoomInfo(date) {
const LINKS = {
K10:
"https://us02web.zoom.us/j/88548344770?pwd=aVRTbExFWGkwSllZSjJEMnhYYUN0UT09",
Library:
"https://us02web.zoom.us/j/89818879270?pwd=dXFZZThINVM4T3FDVno4WDFzZmp4Zz09",
Art:
"https://nycdoe.zoom.us/j/89082888518?pwd=dnViaWw5WTBaTnRw WXpJWTZBQmtWUT09",
Science:
"https://us02web.zoom.us/j/83678795208?pwd=aDZPNlV0VEF6ellsc3R2Qll3UGxaUT09",
PE:
"https://us02web.zoom.us/j/89000822442?pwd=ZEd0S1VsR2swbmZZRkxaMjZ1Q21GZz09",
Music:
"https://us02web.zoom.us/j/83075201283?pwd=VEtwTkVvbVZsR0hFemx1Y1NiSnhSQT09",
};
const hour = date.getHours();
const minute = date.getMinutes();
// 9:00 - 9:35 for special classes
if (hour === 9 && minute <= 35) {
const className = getSpecialClassRotation(new Date());
return [className, LINKS[className]];
}
return ["K10", LINKS.K10];
}
function createWidget(title, img, widgeturl) {
let w = new ListWidget();
w.setPadding(0, 0, 0, 0);
w.backgroundColor = new Color("#008bd0");
if (title) {
const titleTxt = w.addText(title);
titleTxt.textColor = Color.white();
titleTxt.font = Font.systemFont(24);
titleTxt.centerAlignText();
}
if (img) {
w.backgroundImage = img;
}
if (widgeturl) {
w.url = widgeturl;
}
return w;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment