-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/2.1.0' into master
- Loading branch information
Showing
18 changed files
with
611 additions
and
175 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,3 @@ | ||
{ | ||
"esversion": 6 | ||
} |
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
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
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,57 @@ | ||
'use strict' | ||
|
||
const moment = require('moment') | ||
const Cache = use('Cache') | ||
const Scrapper = use('Scrapper') | ||
const ScrappingException = use('App/Exceptions/ScrappingException') | ||
|
||
const numberOfWeekByMonth = 4 | ||
|
||
class MonthController { | ||
/** | ||
* Get courses of the current month | ||
*/ | ||
async getCurrent ({ request }) { | ||
const { firstname, lastname, ignoreCache } = request.only(['firstname', 'lastname', 'ignoreCache']) | ||
|
||
const result = [] | ||
|
||
for (let i = 0; i < numberOfWeekByMonth; i++) { | ||
let cacheUsed = false | ||
// get current date (+ i * 7 days) and format with moment | ||
const date = moment(new Date()).add(i * 7, 'd').format('MM/DD/YY') | ||
|
||
// --------------------------------------------------- | ||
// Use cache (or at least, try to) | ||
|
||
if (!ignoreCache) { | ||
// Get data from cache | ||
const data = await Cache.getWeek(firstname, lastname, date) | ||
if (data) { | ||
cacheUsed = true | ||
result.push(data) | ||
} | ||
} | ||
|
||
// --------------------------------------------------- | ||
// Data not in cache: scrapping | ||
|
||
if (ignoreCache || !cacheUsed) { | ||
// if not cached, scrap it | ||
const data = await Scrapper.fetchWeek(firstname, lastname, date) | ||
.catch(() => { /* istanbul ignore next */ throw new ScrappingException() }) | ||
|
||
result.push(data) | ||
|
||
// set scrap result in cache | ||
await Cache.setWeek(firstname, lastname, date, data) | ||
// indicate to not restart scrapping today | ||
await Cache.setIsDailyScrapped(firstname, lastname, date) | ||
} | ||
} | ||
|
||
return result | ||
} | ||
} | ||
|
||
module.exports = MonthController |
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,20 @@ | ||
'use strict' | ||
|
||
const Scrapper = use('Scrapper') | ||
const ScrappingException = use('App/Exceptions/ScrappingException') | ||
|
||
class TeamsController { | ||
/** | ||
* Get Microsoft Teams current links | ||
*/ | ||
async get ({ request }) { | ||
const { firstname, lastname } = request.only(['firstname', 'lastname']) | ||
|
||
const result = await Scrapper.fetchTeamsLinks(firstname, lastname) | ||
.catch(() => { /* istanbul ignore next */ throw new ScrappingException() }) | ||
|
||
return result | ||
} | ||
} | ||
|
||
module.exports = TeamsController |
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
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,55 @@ | ||
/* istanbul ignore file */ | ||
'use strict' | ||
|
||
const ical = require('ical-generator') | ||
const moment = require('moment') | ||
|
||
class ConvertIcal { | ||
async handle ({ response, request }, next) { | ||
await next() | ||
|
||
const format = request.input('format') | ||
|
||
if (format === 'icalendar') { | ||
const cal = ical() | ||
|
||
const events = findValuesHelper(response._lazyBody, 'date', []) | ||
|
||
events.forEach(event => { | ||
cal.createEvent({ | ||
start: moment(event.date + ' ' + event.start, 'DD/MM/YYYY hh:mm').toDate(), | ||
end: moment(event.date + ' ' + event.end, 'DD/MM/YYYY hh:mm').toDate(), | ||
summary: event.subject, | ||
description: event.professor, | ||
location: event.room | ||
}) | ||
}) | ||
|
||
response._lazyBody.content = cal.toString() | ||
response.safeHeader('Content-type', 'text/calendar') | ||
} | ||
} | ||
} | ||
|
||
function findValuesHelper (obj, key, list) { | ||
if (!obj) return list | ||
if (obj instanceof Array) { | ||
for (var i in obj) { | ||
list = list.concat(findValuesHelper(obj[i], key, [])) | ||
} | ||
return list | ||
} | ||
if (obj[key]) list.push(obj) | ||
|
||
if ((typeof obj === 'object') && (obj !== null)) { | ||
var children = Object.keys(obj) | ||
if (children.length > 0) { | ||
for (i = 0; i < children.length; i++) { | ||
list = list.concat(findValuesHelper(obj[children[i]], key, [])) | ||
} | ||
} | ||
} | ||
return list | ||
} | ||
|
||
module.exports = ConvertIcal |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.