-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split features into separate folders and implement new code replace f…
…unction
- Loading branch information
Showing
4 changed files
with
154 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
|
||
```js | ||
// your feature | ||
// @author : your github username | ||
// @date : the date you created this file | ||
// @description : a short description of what your feature does | ||
// @params : any parameters your feature needs | ||
// @returns : what your feature returns | ||
// @notes : any notes you want to add | ||
|
||
function run(cal) { | ||
// your code | ||
|
||
return cal | ||
} | ||
|
||
module.exports = { | ||
run, | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Forcing calenders to update events once a day | ||
// @author : aap9002 | ||
// @date : 01/11/2023 | ||
// @description : once a day between 01:00 and 04:00, force a refresh of the events to restyle any new formatting | ||
// @params : the calender in string format | ||
// @returns : the calender in string format | ||
// @notes : Be aware the time is based on the server time not UTC | ||
|
||
const regex = /^LAST-MODIFIED:.*/gm; | ||
|
||
/** | ||
* Force events to update format once a day | ||
* @param {string} cal | ||
* @returns cal with last modified date time set | ||
*/ | ||
function run(cal) { | ||
// once a day between 01:00 and 04:00, force a refresh of the events to restyle any new formatting | ||
// this is as modifications to the event will not be recognised and updated unless the UoM event changes on the timetabling system itself | ||
// so this will manual set the last modified each day to force an update in the calender app | ||
// NB. it will stop doing this at 4 am so any changes in the day will be recognised and updated live | ||
// NB. 3 hour window set as the ICS is set to refresh evert 2 hours, so this should affect all users | ||
const date = new Date(); | ||
const hour = date.getHours(); | ||
if (hour >= 1 && hour <= 4) { | ||
datestr = date.toISOString().split('T')[0]; | ||
datestr = datestr.split('-').join(''); | ||
datestr = "LAST-MODIFIED:" + datestr + "T000000"; | ||
cal = cal.replace(regex, datestr); | ||
} | ||
|
||
return cal; | ||
} | ||
|
||
module.exports = { | ||
run, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Replace course codes | ||
// @author : aap9002 | ||
// @date : 01/11/2023 | ||
// @description : Find and replace course codes with [course names] or [course code and course name] | ||
// @params : the calender in string format | ||
// @returns : the calender in string format | ||
|
||
|
||
const pattern = /SUMMARY:[^\/]*\//g // REGEX to search the ICAL for the course code | ||
|
||
/** | ||
* List unique course names in the string | ||
* @param {string} cal | ||
* @returns List of unique course codes | ||
*/ | ||
function parseCourseCodes(cal) { | ||
const uniqueMatches = new Set(); | ||
|
||
let match; | ||
while ((match = pattern.exec(cal)) !== null) { | ||
//console.log(match[0].split(':')[1].split('/')[0]); | ||
uniqueMatches.add(match[0].split(':')[1].split('/')[0]); | ||
} | ||
const uniqueCourseCodesArray = Array.from(uniqueMatches); | ||
return uniqueCourseCodesArray; | ||
} | ||
|
||
/** | ||
* Replace course codes with full course names | ||
* @param {string} cal | ||
* @returns cal with replacements | ||
*/ | ||
function replaceCourseCodesWithNames(cal, courses) { | ||
// get unique course codes | ||
let uniqueCourseCodesArray = parseCourseCodes(cal); | ||
|
||
// replace course codes with names | ||
for (let i = 0; i < uniqueCourseCodesArray.length; i++) { | ||
const courseCode = uniqueCourseCodesArray[i]; | ||
try { | ||
const courseName = courses.find(course => course.split(' ')[0] === courseCode).split(' ').slice(1).join(' '); | ||
cal = cal.split(courseCode).join(courseName); | ||
} | ||
catch (e) { | ||
// if the course code is not found in the allCourses.md file, log it | ||
console.log(courseCode + " not found in allCourses.md"); | ||
} | ||
} | ||
|
||
return cal; | ||
} | ||
|
||
/** | ||
* Replace course codes with code and full course names | ||
* @param {string} cal | ||
* @returns cal with replacements | ||
*/ | ||
function replaceCourseCodesWithCodeAndNames(cal, courses) { | ||
// get unique course codes | ||
let uniqueCourseCodesArray = parseCourseCodes(cal); | ||
|
||
// replace course codes with names | ||
for (let i = 0; i < uniqueCourseCodesArray.length; i++) { | ||
const courseCode = uniqueCourseCodesArray[i]; | ||
try { | ||
const courseName = courses.find(course => course.split(' ')[0] === courseCode).split(' ').slice(1).join(' '); | ||
cal = cal.split(courseCode).join(courseCode + " " + courseName); | ||
} | ||
catch (e) { | ||
// if the course code is not found in the allCourses.md file, log it | ||
console.log(courseCode + " not found in allCourses.md"); | ||
} | ||
} | ||
|
||
return cal; | ||
} | ||
|
||
module.exports = { | ||
replaceCourseCodesWithNames, | ||
replaceCourseCodesWithCodeAndNames | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters