-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlesson.js
75 lines (56 loc) · 1.9 KB
/
lesson.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var cheerio = require('cheerio'),
request = require('request'),
ncl = require('ncl-connect');
exports.getModules = function(user, callback) {
ncl.getPage(user, 'https://lesson.cs.ncl.ac.uk/', function(error, $)
{
if(error)
return callback(error);
var modules = [];
$('article .span3').each(function() {
if($(this).find('ul').text().trim() == '')
return;
var module = {
name: $(this).find('h2').text().trim()
};
$(this).find('ul li').each(function() {
var name = $(this).find('a').text().trim();
if(name == 'Links')
module.links = true;
else if(name == 'Media')
module.media = true;
});
modules.push(module);
});
callback(null, modules);
});
}
exports.getMediaList = function(module, user, callback) {
ncl.getPage(user, 'https://lesson.cs.ncl.ac.uk/module/' + module + '/media', function(error, $)
{
if(error)
return callback(error);
var mediaList = [];
$('article .span3').each(function() {
if($(this).find('ul').text().trim() == '')
return;
$(this).find('ul li').each(function() {
var $a = $(this).find('a');
var media = {
name: $a.text().trim(),
link: $a.attr('href').split('/').slice(-1)[0]
};
mediaList.push(media);
});
});
callback(null, mediaList);
});
}
exports.getMedia= function(module, media, user, callback) {
ncl.getPage(user, 'https://lesson.cs.ncl.ac.uk/module/' + module + '/' + media, function(error, $)
{
if(error)
return callback(error);
callback(null, $('article').html());
});
}