성준영

reload dir

1 +node_modules/
...\ No newline at end of file ...\ No newline at end of file
1 +MIT License
2 +
3 +Copyright (c) 2017 Junyoung, Sung
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining a copy
6 +of this software and associated documentation files (the "Software"), to deal
7 +in the Software without restriction, including without limitation the rights
8 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 +copies of the Software, and to permit persons to whom the Software is
10 +furnished to do so, subject to the following conditions:
11 +
12 +The above copyright notice and this permission notice shall be included in all
13 +copies or substantial portions of the Software.
14 +
15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 +SOFTWARE.
1 +# klas-file-downloader
2 +Project that download lecture reference files from Klas
3 +
4 +> If your KLAS password include Exclamation mark, You must write your password like `\!`. for example,
5 +
6 +```
7 +klasFileDownloader -i 2012104095 -p \!123123123
8 +```
...\ No newline at end of file ...\ No newline at end of file
1 +/**
2 + * Created by junyoung on 2017. 4. 2..
3 + */
4 +
5 +var request = require('request');
6 +var cheerio = require('cheerio');
7 +var Promise = require('promise');
8 +const readline = require('readline');
9 +var https = require('https');
10 +var querystring = require('querystring');
11 +
12 +var Iconv = require('iconv').Iconv;
13 +var iconv = new Iconv('euc-kr', 'utf-8//translit//ignore');
14 +
15 +
16 +var j = request.jar();
17 +request = request.defaults({jar: j});
18 +
19 +exports.login = function (id, pw) {
20 + return new Promise(function (resolve, reject) {
21 + request({
22 + url: "https://klas.khu.ac.kr/user/loginUser.do",
23 + method: "POST",
24 + form: {USER_ID: id, PASSWORD: pw}
25 + }, function (err, res, body) {
26 +
27 + if (err) {
28 + reject('ERROR');
29 + } else {
30 + resolve(body);
31 + }
32 + })
33 + });
34 +};
35 +
36 +
37 +exports.getLecture = function () {
38 +
39 + return new Promise(function (resolve, reject) {
40 + request({
41 + url: "https://klas.khu.ac.kr/classroom/viewClassroomCourseMoreList.do?courseType=ing",
42 + method: "GET"
43 + }, function (err, res, body) {
44 + if (err) {
45 + reject(err);
46 + } else {
47 + resolve(body);
48 + }
49 + })
50 + })
51 +};
52 +
53 +exports.getLectureLink = function (getLectureBody) {
54 +
55 + return new Promise(function (resolve, reject) {
56 + var $ = cheerio.load(getLectureBody);
57 + var lectureLinks = $('.gomy_class');
58 + var tableTrs = $('#tbl > tbody > tr > td');
59 +
60 + var lectureLinkList = [];
61 +
62 + tableTrs.each(function (i) {
63 + if (i % 7 === 1) {
64 + lectureLinkList.push({lectureName: $(this).text()});
65 + }
66 + });
67 +
68 +
69 + lectureLinks.each(function (i) {
70 + // lectureLinkList[i].link = $(this).attr('href')
71 + lectureLinkList[i].link = 'https://klas.khu.ac.kr' + $(this).attr('href')
72 + });
73 +
74 + resolve(lectureLinkList);
75 +
76 + })
77 +};
78 +
79 +exports.selectLecture = function (lectureLinkList) {
80 +
81 + const rl = readline.createInterface({
82 + input: process.stdin,
83 + output: process.stdout
84 + });
85 + var selectQuestion = '';
86 + selectQuestion += '\n 강의자료를 다운받을 강의를 선택해 주세요 \n';
87 + var count = 0;
88 +
89 + return new Promise(function (resolve, reject) {
90 +
91 + for (var i in lectureLinkList) {
92 + count += 1;
93 + selectQuestion += ' ' + count + '. ' + lectureLinkList[i].lectureName + '\n';
94 + }
95 + selectQuestion += '\n';
96 + selectQuestion += ' 입력 (1 ~ ' + count + ') : ';
97 +
98 +
99 + rl.question(selectQuestion, (answer) => {
100 +
101 + answer = parseInt(answer) - 1;
102 + resolve(lectureLinkList[answer]);
103 +
104 + rl.close();
105 + });
106 + });
107 +
108 +};
109 +
110 +exports.getClassPageBody = function (lectureLink) {
111 +
112 + return new Promise(function (resolve, reject) {
113 +
114 + var url = lectureLink.link;
115 +
116 + var headers = {
117 + 'Cookie': 'COURSE_MENU_NAME=%uAC15%uC758%uC2E4',
118 + 'User-Agent': 'request'
119 + };
120 +
121 + request({
122 + url: url,
123 + mothod: 'GET',
124 + jar: j,
125 + headers: headers
126 + }, function (err, res, body) {
127 + if (err) {
128 + reject(err);
129 + } else {
130 + resolve(body);
131 + }
132 + })
133 + })
134 +};
135 +
136 +exports.findFiles = function (classPageBody) {
137 +
138 + return new Promise(function (resolve, reject) {
139 + var $ = cheerio.load(classPageBody);
140 + var fileDownAnchors = $('.file-downbox-list > ul > li > a');
141 +
142 + fileDownAnchors.each(function (i) {
143 + console.log($(this).attr('href'));
144 + });
145 + })
146 +};
...\ No newline at end of file ...\ No newline at end of file
1 +#!/usr/bin/env node
2 +
3 +var args = require('args');
4 +var functions = require('./functions');
5 +
6 +args
7 + .option('id', 'Your Student ID of KHU, Required')
8 + .option('pw', 'Your Password of KHU, It is never exploited, Required')
9 + .option('lectureBefore', '0 is default, 1 2 .. wil download past lecture reference files')
10 + .option('downloadPath', 'default ~/Downlaod/Klas, will determine download location')
11 +
12 +const flags = args.parse(process.argv);
13 +
14 +if (!flags.id) {
15 + console.log('id is required!');
16 + return;
17 +} else if (!flags.pw) {
18 + console.log('pw is required!');
19 + return;
20 +}
21 +
22 +
23 +functions.login(flags.id, flags.pw)
24 + .then(functions.getLecture)
25 + .then(functions.getLectureLink)
26 + .then(functions.selectLecture)
27 + .then(functions.getClassPageBody)
28 + .then(functions.findFiles)
29 + .then(function(result){
30 + console.log(result);
31 + })
32 + .catch(function (err) {
33 + console.log(err);
34 + });
35 +
36 +
1 +{
2 + "name": "klas-file-downloader",
3 + "version": "0.0.1",
4 + "description": "Project that download lecture reference files from Klas",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "repository": {
10 + "type": "git",
11 + "url": "git+https://github.com/sungjunyoung/klas-file-downloader.git"
12 + },
13 + "keywords": [
14 + "klas",
15 + "file",
16 + "download",
17 + "lecture"
18 + ],
19 + "author": "sungjunyoung",
20 + "license": "MIT",
21 + "bugs": {
22 + "url": "https://github.com/sungjunyoung/klas-file-downloader/issues"
23 + },
24 + "bin": {
25 + "klasFileDownloader": "./index.js"
26 + },
27 + "homepage": "https://sungjunyoung.github.io",
28 + "dependencies": {
29 + "args": "^2.4.1",
30 + "cheerio": "^0.22.0",
31 + "iconv": "^2.2.1",
32 + "promise": "^7.1.1",
33 + "querystring": "^0.2.0",
34 + "request": "^2.81.0"
35 + }
36 +}