summaryrefslogtreecommitdiff
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
parentff55990f746c798dfee084f03fe4c1391c5ccc34 (diff)
downloadmongo-edu-e8d11353bc996339fe9d9c59d27908946af898bd.zip
version bump
handle current and completed courses
-rw-r--r--lib/configure.js2
-rw-r--r--lib/courseware.js2
-rw-r--r--lib/initialize.js2
-rw-r--r--lib/login.js49
-rw-r--r--lib/options.js2
-rw-r--r--lib/prompts.js2
-rw-r--r--lib/validate.js2
-rw-r--r--lib/videos.js2
-rw-r--r--mongo-edu.js2
-rw-r--r--package.json18
10 files changed, 49 insertions, 34 deletions
diff --git a/lib/configure.js b/lib/configure.js
index c83f2f3..35c5855 100644
--- a/lib/configure.js
+++ b/lib/configure.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
*/
diff --git a/lib/courseware.js b/lib/courseware.js
index 47d9b41..b2da4f2 100644
--- a/lib/courseware.js
+++ b/lib/courseware.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
*/
diff --git a/lib/initialize.js b/lib/initialize.js
index 619210b..195423a 100644
--- a/lib/initialize.js
+++ b/lib/initialize.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
*/
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)));
diff --git a/lib/options.js b/lib/options.js
index 273d7d9..11ae37a 100644
--- a/lib/options.js
+++ b/lib/options.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
*/
diff --git a/lib/prompts.js b/lib/prompts.js
index e29716d..ac2aa7a 100644
--- a/lib/prompts.js
+++ b/lib/prompts.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
*/
diff --git a/lib/validate.js b/lib/validate.js
index 4b561d4..2e5ea61 100644
--- a/lib/validate.js
+++ b/lib/validate.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
*/
diff --git a/lib/videos.js b/lib/videos.js
index 2431a53..b7480fe 100644
--- a/lib/videos.js
+++ b/lib/videos.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
*/
diff --git a/mongo-edu.js b/mongo-edu.js
index e798574..ac5b284 100644
--- a/mongo-edu.js
+++ b/mongo-edu.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
*/
diff --git a/package.json b/package.json
index 84316d8..690e2a0 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "mongo-edu",
"preferGlobal": true,
- "version": "0.2.30",
+ "version": "0.2.31",
"author": "Przemyslaw Pluta <przemyslawplutadev@gmail.com> (http://przemyslawpluta.com)",
"description": "Select and download videos and handouts from university.mongodb.com courses",
"main": "./mongo-edu",
@@ -33,21 +33,21 @@
"cheerio": "~0.19.0",
"colors": "~1.1.2",
"easy-table": "~1.0.0",
- "extract-zip": "~1.2.0",
- "filesize": "~3.1.4",
- "glob": "~6.0.1",
- "inquirer": "~0.11.0",
+ "extract-zip": "~1.4.0",
+ "filesize": "~3.1.5",
+ "glob": "~6.0.3",
+ "inquirer": "~0.11.1",
"lodash": "~3.10.1",
"mkdirp": "~0.5.1",
"mv": "~2.1.1",
"path-extra": "~3.0.0",
- "pretty-error": "~1.2.0",
+ "pretty-error": "~2.0.0",
"progress": "~1.1.8",
"request": "~2.67.0",
"request-progress": "~0.4.0",
- "rimraf": "~2.4.4",
- "which": "~1.2.0",
- "yargs": "~3.30.0",
+ "rimraf": "~2.5.0",
+ "which": "~1.2.1",
+ "yargs": "~3.31.0",
"youtube-dl": "~1.10.5"
},
"engines": {