mirror of
https://github.com/ION606/rpi-utils.git
synced 2026-05-14 21:06:54 +00:00
migrated to express.js
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
.calDownload {
|
||||
color: #e7e5e5;
|
||||
background-color: #2d63c8;
|
||||
font-size: 19px;
|
||||
border: 1px solid #2d63c8;
|
||||
padding: 15px 50px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
.calDownload:hover {
|
||||
color: #2d63c8;
|
||||
background-color: #e7e5e5;
|
||||
}
|
||||
|
||||
|
||||
.ogCal {
|
||||
color: #e7e5e5;
|
||||
background-color: #c82d31;
|
||||
font-size: 20px;
|
||||
border: 1px solid #2d63c8;
|
||||
padding: 10px 45px;
|
||||
letter-spacing: 1px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
.ogCal:hover {
|
||||
color: #c82d31;
|
||||
background-color: #e7e5e5;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #ffffff;
|
||||
font-weight: 120;
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
body {
|
||||
/* color: rgb(148, 0, 0); */
|
||||
color: rgb(252, 252, 252);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
body {
|
||||
margin: 0;
|
||||
background-color: rgb(110, 110, 110)
|
||||
}
|
||||
|
||||
.topnav {
|
||||
overflow: hidden;
|
||||
background-color: #333;
|
||||
text-align: center;
|
||||
align-items: center;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.topnav a {
|
||||
/* float: left; */
|
||||
color: #f2f2f2;
|
||||
text-align: center;
|
||||
padding: 20px 20px;
|
||||
text-decoration: none;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.topnav a:hover {
|
||||
background-color: #ddd;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.topnav a.active {
|
||||
background-color: #aa0404;
|
||||
color: white;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" type="text/css" href="/calendar.css" defer>
|
||||
<link rel="stylesheet" type="text/css" href="/navbar.css" defer>
|
||||
<title>RPI Academic Calendar to ics</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="topnav">
|
||||
<a href="/">Home</a>
|
||||
<a class="active" href="calendar">Calendar</a>
|
||||
</div>
|
||||
|
||||
<h1>Academic Calendar</h1>
|
||||
<div style="margin-top: 50px; text-align: center;">
|
||||
<a class="calDownload" href="/createCalendar/" download="rpievents.ics">Download ICS file</a>
|
||||
<br style="margin-bottom: 70px;">
|
||||
<a class="ogCal" href="https://info.rpi.edu/registrar/academic-calendar">RPI Web Page</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" type="text/css" href="/main.css" defer>
|
||||
<link rel="stylesheet" type="text/css" href="/navbar.css" defer>
|
||||
|
||||
<title>RPI Utils Website</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="topnav">
|
||||
<a class="active" href="/">Home</a>
|
||||
<a href="calendar">Calendar</a>
|
||||
</div>
|
||||
|
||||
<div style="text-align: center;">
|
||||
<h1>Welcome to RPI Utils!</h1>
|
||||
<h2>The place with the tools to withstand RPI's terrible online presence!</h2>
|
||||
|
||||
<br style="margin-top: 30px;">
|
||||
<script type="text/javascript" src="https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js" data-name="bmc-button" data-slug="ion606" data-color="#FFDD00" data-emoji="" data-font="Cookie" data-text="Buy me a coffee" data-outline-color="#000000" data-font-color="#000000" data-coffee-color="#ffffff"></script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -2,89 +2,123 @@ const axios = require('axios');
|
||||
const cheerio = require('cheerio');
|
||||
const ics = require('ics');
|
||||
const fs = require('fs');
|
||||
const express = require('express');
|
||||
|
||||
|
||||
const app = express();
|
||||
app.use('/CSS', express.static('./CSS'));
|
||||
app.use('/HTML', express.static('./HTML'));
|
||||
const url = "https://info.rpi.edu/registrar/academic-calendar";
|
||||
const m = new Map();
|
||||
|
||||
|
||||
async function main() {
|
||||
// const data = await fetch(url);
|
||||
// console.log(await data.text());
|
||||
await axios.get(url)
|
||||
.then(res => {
|
||||
const $ = cheerio.load(res.data)
|
||||
const calendar = $('#academicCalendar');
|
||||
for (child of calendar.get(0).children) {
|
||||
if (child.name) {
|
||||
// if (child.attributes)
|
||||
var tag;
|
||||
const c = new Map();
|
||||
for (sub of child.children) {
|
||||
if (sub.name == 'thead') {
|
||||
tag = sub.children[0].children[0].children[0].data;
|
||||
} else {
|
||||
for (tr of sub.children) {
|
||||
const tchildren = tr.children;
|
||||
const d = tchildren.find((c) => (c.attribs.class == "date"));
|
||||
const a = tchildren.find((c) => (c.attribs.class != "date"));
|
||||
const txt = a.children[0].children[0].data;
|
||||
const href = a.children[0].attribs.href;
|
||||
c.set(d.children[0].data, new Map([['txt', txt], ['href', href]]));
|
||||
async function createIcs() {
|
||||
return new Promise(async (resolve) => {
|
||||
const m = new Map();
|
||||
|
||||
await axios.get(url)
|
||||
.then(res => {
|
||||
const $ = cheerio.load(res.data)
|
||||
const calendar = $('#academicCalendar');
|
||||
for (child of calendar.get(0).children) {
|
||||
if (child.name) {
|
||||
// if (child.attributes)
|
||||
var tag;
|
||||
const c = new Map();
|
||||
for (sub of child.children) {
|
||||
if (sub.name == 'thead') {
|
||||
tag = sub.children[0].children[0].children[0].data;
|
||||
} else {
|
||||
for (tr of sub.children) {
|
||||
const tchildren = tr.children;
|
||||
const d = tchildren.find((c) => (c.attribs.class == "date"));
|
||||
const a = tchildren.find((c) => (c.attribs.class != "date"));
|
||||
const txt = a.children[0].children[0].data;
|
||||
const href = a.children[0].attribs.href;
|
||||
c.set(d.children[0].data, new Map([['txt', txt], ['href', href]]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m.set(tag, c);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const events = [];
|
||||
const unused = [];
|
||||
for (const i of m) {
|
||||
for (const j of i[1]) {
|
||||
const key = j[0];
|
||||
const val = j[1];
|
||||
var startDate;
|
||||
var endDate;
|
||||
|
||||
if (key.indexOf("-") != -1) {
|
||||
const keySplit = key.split(" - ");
|
||||
startDate = new Date(keySplit[0]);
|
||||
endDate = new Date(keySplit[1]);
|
||||
} else {
|
||||
startDate = new Date(key);
|
||||
endDate = new Date(key);
|
||||
endDate.setDate(startDate.getDate() + 1);
|
||||
}
|
||||
|
||||
m.set(tag, c);
|
||||
const timesStart = [startDate.getFullYear(), startDate.getMonth() + 1, startDate.getDate(), 0, 0];
|
||||
const timesEnd = [endDate.getFullYear(), endDate.getMonth() + 1, endDate.getDate(), 0, 0];
|
||||
|
||||
events.push({
|
||||
calName: "RPI Academic Calendar",
|
||||
title: val.get("txt"),
|
||||
url: val.get("href"),
|
||||
location: val.get('href'),
|
||||
start: timesStart,
|
||||
end: timesEnd
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ics.createEvents(events, (error, value) => {
|
||||
if (error) {
|
||||
console.log(error)
|
||||
}
|
||||
|
||||
// console.log(value);
|
||||
resolve(value);
|
||||
// fs.writeFileSync(`${__dirname}/rpievents.ics`, value)
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
const events = [];
|
||||
const unused = [];
|
||||
for (const i of m) {
|
||||
for (const j of i[1]) {
|
||||
const key = j[0];
|
||||
const val = j[1];
|
||||
var startDate;
|
||||
var endDate;
|
||||
|
||||
if (key.indexOf("-") != -1) {
|
||||
const keySplit = key.split(" - ");
|
||||
startDate = new Date(keySplit[0]);
|
||||
endDate = new Date(keySplit[1]);
|
||||
} else {
|
||||
startDate = new Date(key);
|
||||
endDate = new Date(key);
|
||||
endDate.setDate(startDate.getDate() + 1);
|
||||
}
|
||||
|
||||
const timesStart = [startDate.getFullYear(), startDate.getMonth() + 1, startDate.getDate(), 0, 0];
|
||||
const timesEnd = [endDate.getFullYear(), endDate.getMonth() + 1, endDate.getDate(), 0, 0];
|
||||
|
||||
events.push({
|
||||
calName: "RPI Academic Calendar",
|
||||
title: val.get("txt"),
|
||||
url: val.get("href"),
|
||||
location: val.get('href'),
|
||||
start: timesStart,
|
||||
end: timesEnd
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ics.createEvents(events, (error, value) => {
|
||||
if (error) {
|
||||
console.log(error)
|
||||
}
|
||||
|
||||
fs.writeFileSync(`${__dirname}/rpievents.ics`, value)
|
||||
})
|
||||
|
||||
// console.log(m.entries().next());
|
||||
|
||||
}
|
||||
|
||||
|
||||
main();
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.sendFile('index.html', {root: 'HTML'});
|
||||
});
|
||||
|
||||
app.get('/calendar', (req, res) => {
|
||||
res.sendFile('calendar.html', {root: 'HTML'});
|
||||
})
|
||||
|
||||
|
||||
app.get('/calendar.css', (req, res) => {
|
||||
return res.sendFile('calendar.css', { root: 'CSS' });
|
||||
});
|
||||
|
||||
app.get('/main.css', (req, res) => {
|
||||
return res.sendFile('main.css', { root: 'CSS' });
|
||||
});
|
||||
|
||||
app.get('/navbar.css', (req, res) => {
|
||||
return res.sendFile('navbar.css', { root: 'CSS' });
|
||||
});
|
||||
|
||||
|
||||
app.get('/createCalendar', async (req, res) => {
|
||||
res.set({'Content-Disposition': 'attachment; rpievents.ics','Content-Type': 'text/ics'});
|
||||
res.send(await createIcs())
|
||||
});
|
||||
|
||||
app.listen(5000);
|
||||
Reference in New Issue
Block a user