Skip to content

Commit 88bbc74

Browse files
committed
add Server
1 parent cc3a7a9 commit 88bbc74

File tree

8,222 files changed

+1385095
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

8,222 files changed

+1385095
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

assets/airtable.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
const Airtable = require("airtable");
2+
const settings = require("../settings.json");
3+
const colors = require("./json/tagColors.json");
4+
5+
const API_KEY = "keyIUNtxniyBauoVn";
6+
7+
const fcm = new Airtable({ apiKey: API_KEY }).base("appOXVfqFCJGee5KS");
8+
const emails = new Airtable({ apiKey: API_KEY }).base("apphtMo2vEtgp6IQg");
9+
const tags = new Airtable({ apiKey: API_KEY }).base("appHe5CWHGqSHbejn");
10+
11+
exports.getFCMTokensForUsers = async function (users = []) {
12+
var tokens = [];
13+
console.log("[Info] Getting tokens for", users.length, "users");
14+
await Promise.all(
15+
await users.map(
16+
async (uid) =>
17+
await fcm("FCM Tokens")
18+
.select({
19+
filterByFormula: `{uid} = \"${uid}\"`,
20+
})
21+
.all()
22+
.then(async (res) => {
23+
res.forEach((elem) => {
24+
tokens.push(elem.fields.token);
25+
});
26+
})
27+
.catch((err) => {
28+
console.warn("Could not get uid tokens from airtable", err);
29+
30+
return [];
31+
})
32+
)
33+
);
34+
tokens = [...new Set(tokens)]; // Remove duplicates
35+
console.log("[Info] Received", tokens.length, "tokens");
36+
return tokens;
37+
};
38+
39+
const getAllTags = async function () {
40+
return tags("Colors")
41+
.select()
42+
.all()
43+
.then((tags) => {
44+
return tags.map((elem) => {
45+
return {
46+
tag: elem.fields.Tag,
47+
name: elem.fields.Tag,
48+
value: elem.fields.Tag,
49+
color: elem.fields.Color,
50+
}; // Make key names lowerCase and suitable for enquirer
51+
});
52+
})
53+
.catch((err) => {
54+
throw err;
55+
});
56+
};
57+
exports.getAllTags = getAllTags;
58+
exports.createTag = async function (tag) {
59+
const existingTags = await getAllTags();
60+
61+
if (existingTags.every((elem) => elem.tag !== tag)) {
62+
const color = colors[Math.floor(Math.random() * colors.length)];
63+
tags("Colors")
64+
.create({
65+
Tag: tag,
66+
Color: color,
67+
})
68+
.then(() => {
69+
console.log("[Info] Created tag '" + tag + "'");
70+
return { tag: tag };
71+
})
72+
.catch((err) => {
73+
settings.debugErrors && console.trace("[Error]", err);
74+
return { error: err };
75+
});
76+
} else console.log("[Info] Tag '" + tag + "' already existss");
77+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "service_account",
3+
"project_id": "campus42",
4+
"private_key_id": "b97f4f6a0dba9dc045f9e2cb48e54e240ed0a895",
5+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC/5x8Zn+0bOG+c\n7LWzKXzRVbQI/mAznfgk9xPPGfwyyaYR7Ub6Nx6pyFrZ9e15v/6SiN25aUR7e7Q9\nHf24UBDYCUw0khDl8jjeIOPjybSqo7Yjy3W50s0V/ZBQa1/Zq4wDrYpkQl342RP1\nRkP4iYbGR+uSMmmSXoRmcTONla03iZAjdmLf4LTCmoIi4zYStGxiZV7diz884hST\nGRyCqjeK/uqu27J/CYO1SP68dobSVQxHPT87SMmsY1yxANgqu3AY8OKInBhYpX8Y\n8/Y1Is6bQoW5iU+bwcjQWNAcgcuncpt/9em3W7iKz96lfP4Pkq0Z3dOdUAvf0ENt\nQFhM7zfnAgMBAAECggEAAQvCpAi2toYRbBEjBGQrfzCXMWon60aAvbxv0GcoQSNp\nBk8wXdjDEAXWVbqWnfbculiIoAp7PXkOu6G+nXlb175lOrwfeQ4shSyeUVvq4is2\nQoevXC3r9Dy6w28L/LG7ETuqHDwuxImnJ2UUpcKKIem7PPbAk8DahxYC3YV9UwCO\n7DQ9uXACSqFbo8cL8mHtsLfRnEZSCaTVN+Y6+lsGPBG+kTE7RpVp+lCkIEnl5yyC\n0tlPkNvLh1jJ5SiBEQXMH/1H73LcDgHFi92RONMMT20DntWm0eLGneY8+ouI21wp\n+t/XIpWoZPGiBGNzhURoV+l8+u5DlDZiPytYDAGFMQKBgQDn1A4dg6hOeESq6PHV\n2/jhghvL1nz2mqz5asQQvY4F6ty2jc8dRgKtAb9AqqUf66Y8KCLMKd+l4l81EaNk\n5iiokW2UczLacUs2N7Uq4ssJGaav7rxT2VLUs9zz9zzOe6A/7LAjmlQ5uvltO6FT\n2K9sgcPLdU52LkbZjYn8oQlUbQKBgQDT6WCU/9DRVcRNq0KzwiVF5cyiukbSQ0SK\nuOykJbe4uamhimcfiDpTBoREI9xx4vIu5WKuScUr25AFi98nEKO7EYrP/1dAJkI8\n0BtTyNUYTVhKSlGsrqftm3DpDtPlBdKLR27C8SxZHO77SdhKPKw0Cb7NqUO6VUEh\nF57W1X1BIwKBgQDlmYx9SKaJSO3hQyI4h0rftSdoYz6SUjCcOVSDq+icDbaYiqwk\ntvDxfbh4CEnP6mhSTgHgqFwbA679dUGZLaX5BUc87jbgR7KQuO2R0tn5YlFHDy+v\n753skVJ0wVmUurXEedsc970RDA/6UkN+Mi3TTlWnDMAvpbd/wYF3FdqSpQKBgHqS\n/36wCgVL6uRSL57yqcSoi5mEzfpJVpg3Jwo7lu2O1wPNnqCql7H2jwMrCxQFBbkC\njfXqTdZ0hfXvVgCuq0ZFe1mchMdiWeX7KhNok3ofIva1zlBoJlJWGxVzsjVDDOnr\nQ7IW9mQFTGal7CnktmbTTD6Brd9V+Po/Q21Yx76pAoGBAN6VKzoyrMkm0qZvFqOw\nGE8VgKsZGwiLuP8neqBFFiyNAFyp1sCK7pR8WdHyCk7C5Me0Q9Rr/NX7YGvIpUTf\npREAkHLMXBsLBoCxQmmKpHu+66exHzC7Dy4NyAbPNpLGgQlXqkaEytY9gtPMmAXa\ndWk3rt4YrHjBxgCDXd75REjw\n-----END PRIVATE KEY-----\n",
6+
"client_email": "[email protected]",
7+
"client_id": "113137761909559070249",
8+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
9+
"token_uri": "https://oauth2.googleapis.com/token",
10+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-nda4u%40campus42.iam.gserviceaccount.com"
12+
}

assets/campuses.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.campuses = ["university_of_buckingham", "campus_test"];

assets/date.js

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
const settings = require("../settings.json");
2+
const d3 = require("d3-time-format");
3+
4+
const validDate = (date) => date instanceof Date && !isNaN(date) && date.getTime() !== NaN;
5+
function parseTimeString(timeString) {
6+
const pmHours = timeString.includes("pm") ? 12 : 0; // Add 12 hours if it is in the evening
7+
var numbers = timeString.replace(/\D/g, ":").split(":");
8+
const hours = parseInt(numbers[0]) + pmHours;
9+
const mins = isNaN(numbers[1]) ? 0 : numbers[1] == "" ? 0 : parseInt(numbers[1]) || 0;
10+
return { hours, mins };
11+
}
12+
13+
exports.getDateFromSUEvent = async function (rawDate, time) {
14+
const start = new Date(rawDate);
15+
const end = new Date(rawDate);
16+
17+
if (!time) throw new Error("Non existing event date");
18+
const timeParts = (time || "").split("-");
19+
20+
timeParts.forEach((elem, index) => {
21+
var txt = elem.trim().toLowerCase();
22+
var hour = 0;
23+
var mins = 0;
24+
25+
if (elem.includes("midnight")) {
26+
hour = index == 0 ? 0 : 23;
27+
mins = index == 0 ? 0 : 59;
28+
} else {
29+
const time = parseTimeString(txt);
30+
if (isNaN(time.hours) || isNaN(time.hours)) throw new Error("invalid date");
31+
hour = time.hours;
32+
mins = time.mins;
33+
}
34+
35+
if (index == 0) {
36+
start.setHours(hour);
37+
start.setMinutes(mins, 0, 0);
38+
} else if (index == 1) {
39+
end.setHours(hour);
40+
end.setMinutes(mins, 0, 0);
41+
}
42+
});
43+
44+
return {
45+
start: start,
46+
end: end,
47+
};
48+
};
49+
50+
exports.getMinutesFromDate = async function (minutes = 15) {
51+
const date = new Date();
52+
date.setMinutes(date.getMinutes() + minutes);
53+
return date.getTime();
54+
};
55+
exports.getFutureDateMSInDays = async function (days = 14, date = new Date()) {
56+
const startDate = new Date(date);
57+
startDate.setDate(startDate.getDate() + days);
58+
return startDate.getTime();
59+
};
60+
exports.getFutureDateMSInMinutes = async function (minutes = 15, startDate = new Date()) {
61+
const date = startDate;
62+
date.setMinutes(date.getMinutes() + minutes);
63+
return date.getTime();
64+
};
65+
66+
exports.getClosestRunIntervalDate = async function () {
67+
const date = new Date();
68+
const intervals = [];
69+
// Create the intervals per hour and insert into intervals array
70+
for (var x = 0; x < 60 / settings.scriptInterval; x++) {
71+
intervals.push(x * settings.scriptInterval);
72+
}
73+
// Loop through these intervals and set minutes for and seconds so they match the start of the script time
74+
const dateMins = date.getMinutes();
75+
const len = intervals.length;
76+
77+
for (var i = 0; i < len; i++) {
78+
if (i == len - 1 && dateMins >= intervals[len - 1]) {
79+
date.setMinutes(intervals[i], 0, 0);
80+
} else if (dateMins >= intervals[i] && dateMins < intervals[i + 1]) {
81+
date.setMinutes(intervals[i], 0, 0);
82+
}
83+
}
84+
return date;
85+
};
86+
87+
exports.getFutureDateWithSetHours = async function (hours, mins, secs, days = settings.repeatCreationDaysAdvance) {
88+
const futureDate = new Date();
89+
futureDate.setDate(futureDate.getDate() + days);
90+
91+
futureDate.setHours(hours, mins, secs, 0);
92+
return futureDate;
93+
};

0 commit comments

Comments
 (0)