summaryrefslogtreecommitdiff
path: root/lib/login.js
diff options
context:
space:
mode:
authorprzemyslawpluta <przemekpluta@hotmail.com>2016-01-02 16:46:18 +0000
committerprzemyslawpluta <przemekpluta@hotmail.com>2016-01-02 16:46:18 +0000
commite8d11353bc996339fe9d9c59d27908946af898bd (patch)
tree0a8916a1390a17a6ea7f42f3a6244857334c4729 /lib/login.js
parentff55990f746c798dfee084f03fe4c1391c5ccc34 (diff)
downloadmongo-edu-e8d11353bc996339fe9d9c59d27908946af898bd.zip
version bump
handle current and completed courses
Diffstat (limited to 'lib/login.js')
-rw-r--r--lib/login.js49
1 files changed, 32 insertions, 17 deletions
diff --git a/lib/login.js b/lib/login.js
index d99f7ea..ddbbfc4 100644
--- a/lib/login.js
+++ b/lib/login.js
@@ -1,7 +1,7 @@
/*
* mongo-edu
*
- * Copyright (c) 2014-2015 Przemyslaw Pluta
+ * Copyright (c) 2014-2016 Przemyslaw Pluta
* Licensed under the MIT license.
* https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE
*/
@@ -12,6 +12,8 @@ var request = require('request'),
_ = require('lodash'),
videoHandler = require('./videos'),
PrettyError = require('pretty-error'),
+ prompts = require('./prompts'),
+ inquirer = require('inquirer'),
coursewareHandler = require('./courseware');
var jar = request.jar(), host = 'https://university.mongodb.com',
@@ -31,7 +33,7 @@ module.exports = {
'use strict';
var url = host,
- bar = new ProgressBar('>'.magenta + ' Searching [:bar] :percent', { complete: '=', incomplete: ' ', width: 20, total: 7 }),
+ bar = new ProgressBar('>'.magenta + ' Searching [:bar] :percent', { complete: '=', incomplete: ' ', width: 20, total: 6 }),
CSRFTokenCookie = '',
login = function login(token) {
@@ -94,6 +96,32 @@ module.exports = {
},
+ courseSection = function courseSection() {
+ var list = prompts.list;
+ list[0].message = 'Select Courses:';
+ list[0].choices = [{name: 'Current', value: 'tab-current'}, {name: 'Completed', value: 'tab-completed'}];
+ return list;
+ },
+
+ processSelection = function processSelection(body, answers, currentProfile, callback) {
+
+ var list = [], $ = cheerio.load(body),
+ current = $('#' + answers.url),
+ link = current.find('div.section-course').children().find('h4').children(),
+ noCourses = current.find('section.section-courses-empty').text(),
+ findNewCourses = current.find('div.section-courses-empty-buttons a').attr('href');
+
+ $(link).each(function each(i, item) {
+ list.push({ name: $(item).text(), value: url + $(item).attr('href').replace(/about|info|syllabus/g, '') + ((!argv.h) ? (argv.cw || argv.cwd) ? 'courseware' : 'course_wiki' : 'syllabus') });
+ });
+
+ if (noCourses) { currentProfile.noCourses = noCourses.trim().split('\n').map(function items(item) {
+ return item.replace(/ +/g, ' ');
+ }).join('').replace(/ +/g, ' ') + ' at ' + url + findNewCourses + '.\n'; }
+
+ return callback(null, list, currentProfile);
+ },
+
checkCourses = function checkCourses(bar, currentProfile) {
bar.tick();
@@ -105,25 +133,12 @@ module.exports = {
if (res.statusCode === 200) {
- var list = [], $ = cheerio.load(body),
- current = $('#tab-current'),
- link = current.find('div.section-course').children().find('h4').children(),
- noCourses = current.find('section.section-courses-empty').text(),
- findNewCourses = current.find('div.section-courses-empty-buttons a').attr('href');
-
bar.tick();
- $(link).each(function each(i, item) {
- list.push({ name: $(item).text(), value: url + $(item).attr('href').replace(/about|info|syllabus/g, '') + ((!argv.h) ? (argv.cw || argv.cwd) ? 'courseware' : 'course_wiki' : 'syllabus') });
+ return inquirer.prompt(courseSection(), function prompt(answers) {
+ processSelection(body, answers, currentProfile, callback);
});
- bar.tick();
-
- if (noCourses) { currentProfile.noCourses = noCourses.trim().split('\n').map(function items(item) {
- return item.replace(/ +/g, ' ');
- }).join('').replace(/ +/g, ' ') + ' at ' + url + findNewCourses + '.\n'; }
-
- return callback(null, list, currentProfile);
}
callback(pe.render(new Error(res.statusCode)));