성준영

reload dir

node_modules/
\ No newline at end of file
MIT License
Copyright (c) 2017 Junyoung, Sung
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# klas-file-downloader
Project that download lecture reference files from Klas
> If your KLAS password include Exclamation mark, You must write your password like `\!`. for example,
```
klasFileDownloader -i 2012104095 -p \!123123123
```
\ No newline at end of file
/**
* Created by junyoung on 2017. 4. 2..
*/
var request = require('request');
var cheerio = require('cheerio');
var Promise = require('promise');
const readline = require('readline');
var https = require('https');
var querystring = require('querystring');
var Iconv = require('iconv').Iconv;
var iconv = new Iconv('euc-kr', 'utf-8//translit//ignore');
var j = request.jar();
request = request.defaults({jar: j});
exports.login = function (id, pw) {
return new Promise(function (resolve, reject) {
request({
url: "https://klas.khu.ac.kr/user/loginUser.do",
method: "POST",
form: {USER_ID: id, PASSWORD: pw}
}, function (err, res, body) {
if (err) {
reject('ERROR');
} else {
resolve(body);
}
})
});
};
exports.getLecture = function () {
return new Promise(function (resolve, reject) {
request({
url: "https://klas.khu.ac.kr/classroom/viewClassroomCourseMoreList.do?courseType=ing",
method: "GET"
}, function (err, res, body) {
if (err) {
reject(err);
} else {
resolve(body);
}
})
})
};
exports.getLectureLink = function (getLectureBody) {
return new Promise(function (resolve, reject) {
var $ = cheerio.load(getLectureBody);
var lectureLinks = $('.gomy_class');
var tableTrs = $('#tbl > tbody > tr > td');
var lectureLinkList = [];
tableTrs.each(function (i) {
if (i % 7 === 1) {
lectureLinkList.push({lectureName: $(this).text()});
}
});
lectureLinks.each(function (i) {
// lectureLinkList[i].link = $(this).attr('href')
lectureLinkList[i].link = 'https://klas.khu.ac.kr' + $(this).attr('href')
});
resolve(lectureLinkList);
})
};
exports.selectLecture = function (lectureLinkList) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var selectQuestion = '';
selectQuestion += '\n 강의자료를 다운받을 강의를 선택해 주세요 \n';
var count = 0;
return new Promise(function (resolve, reject) {
for (var i in lectureLinkList) {
count += 1;
selectQuestion += ' ' + count + '. ' + lectureLinkList[i].lectureName + '\n';
}
selectQuestion += '\n';
selectQuestion += ' 입력 (1 ~ ' + count + ') : ';
rl.question(selectQuestion, (answer) => {
answer = parseInt(answer) - 1;
resolve(lectureLinkList[answer]);
rl.close();
});
});
};
exports.getClassPageBody = function (lectureLink) {
return new Promise(function (resolve, reject) {
var url = lectureLink.link;
var headers = {
'Cookie': 'COURSE_MENU_NAME=%uAC15%uC758%uC2E4',
'User-Agent': 'request'
};
request({
url: url,
mothod: 'GET',
jar: j,
headers: headers
}, function (err, res, body) {
if (err) {
reject(err);
} else {
resolve(body);
}
})
})
};
exports.findFiles = function (classPageBody) {
return new Promise(function (resolve, reject) {
var $ = cheerio.load(classPageBody);
var fileDownAnchors = $('.file-downbox-list > ul > li > a');
fileDownAnchors.each(function (i) {
console.log($(this).attr('href'));
});
})
};
\ No newline at end of file
#!/usr/bin/env node
var args = require('args');
var functions = require('./functions');
args
.option('id', 'Your Student ID of KHU, Required')
.option('pw', 'Your Password of KHU, It is never exploited, Required')
.option('lectureBefore', '0 is default, 1 2 .. wil download past lecture reference files')
.option('downloadPath', 'default ~/Downlaod/Klas, will determine download location')
const flags = args.parse(process.argv);
if (!flags.id) {
console.log('id is required!');
return;
} else if (!flags.pw) {
console.log('pw is required!');
return;
}
functions.login(flags.id, flags.pw)
.then(functions.getLecture)
.then(functions.getLectureLink)
.then(functions.selectLecture)
.then(functions.getClassPageBody)
.then(functions.findFiles)
.then(function(result){
console.log(result);
})
.catch(function (err) {
console.log(err);
});
{
"name": "klas-file-downloader",
"version": "0.0.1",
"description": "Project that download lecture reference files from Klas",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sungjunyoung/klas-file-downloader.git"
},
"keywords": [
"klas",
"file",
"download",
"lecture"
],
"author": "sungjunyoung",
"license": "MIT",
"bugs": {
"url": "https://github.com/sungjunyoung/klas-file-downloader/issues"
},
"bin": {
"klasFileDownloader": "./index.js"
},
"homepage": "https://sungjunyoung.github.io",
"dependencies": {
"args": "^2.4.1",
"cheerio": "^0.22.0",
"iconv": "^2.2.1",
"promise": "^7.1.1",
"querystring": "^0.2.0",
"request": "^2.81.0"
}
}