Toggle navigation
Toggle navigation
This project
Loading...
Sign in
성준영
/
klas-file-downloader
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
성준영
2017-04-04 15:52:36 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4158a263a36dab3f01ac48aa3e0ee3b1a8270823
4158a263
1 parent
04a3002e
한글화
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
38 deletions
README.md
functions.js
index.js
README.md
View file @
4158a26
> # **IN-DEVELOPING**
# klas-file-downloader
Project that download lecture reference files from Klas
경희대학교 클라스의 강의실 페이지에서 강의자료를 다운받는 npm 패키지입니다.
## INSTALL
```
npm install -g klasFileDownloader
npm install -g klasFileDownloader
```
## USAGE
> **WARNING!!** If your KLAS password include Exclamation mark, You must write your password like `\!`. for example,
> **WARNING!!** 패스워드가 @ 이외의 특수문자를 포함하고 있다면, 패스워드 앞에 \ 를 붙여주어야 합니다.
```
klasFileDownloader -i 2012104095 -p \!123123\*123
```
klasFileDownloader -i 2012104095 -p \!123123\!123
```
\ No newline at end of file
...
...
functions.js
View file @
4158a26
...
...
@@ -11,7 +11,6 @@ var querystring = require('querystring');
var
fs
=
require
(
'fs'
);
var
j
=
request
.
jar
();
request
=
request
.
defaults
({
jar
:
j
});
...
...
@@ -147,7 +146,6 @@ exports.findFiles = function (classPageBody) {
var
tempFileArr
=
[];
$
(
this
).
find
(
'.mycl_veiw_learnig'
).
find
(
'.file-downbox-list'
).
find
(
'a'
).
each
(
function
(
j
)
{
var
link
=
'https://klas.khu.ac.kr'
+
$
(
this
).
attr
(
'href'
).
split
(
'..'
)[
1
];
tempFileArr
.
push
(
link
);
});
fileArr
.
push
(
tempFileArr
);
...
...
@@ -157,8 +155,17 @@ exports.findFiles = function (classPageBody) {
})
};
exports
.
getSelectedFiles
=
function
(
fileArr
,
lectureBefore
)
{
exports
.
getSelectedFiles
=
function
(
fileArr
,
lb
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
lectureBefore
=
0
;
if
(
!
lb
||
lb
===
''
){
lectureBefore
=
0
;
}
else
{
lectureBefore
=
lb
;
}
var
downloadIndex
=
fileArr
.
length
-
lectureBefore
-
1
;
if
(
downloadIndex
<
0
)
{
...
...
@@ -173,15 +180,29 @@ exports.downloadSelectedFile = function (selectedFile, path) {
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
downloadPath
;
if
(
!
path
||
path
===
''
){
downloadPath
=
''
;
//TODO Default Path 설정하기
}
else
{
downloadPath
=
path
;
//TODO 사용자가 지정한 path 리포맷하기
}
var
count
=
0
;
selectedFile
.
forEach
(
function
(
value
,
index
)
{
request
=
https
.
get
(
value
,
function
(
response
)
{
// console.log(response)
;
count
++
;
var
file
=
fs
.
createWriteStream
(
"./file_"
+
index
+
".pdf"
);
response
.
pipe
(
file
);
if
(
index
===
count
)
{
resolve
(
'done'
);
}
});
if
(
index
===
count
-
1
)
{
resolve
(
'done'
);
}
})
})
};
\ No newline at end of file
...
...
index.js
View file @
4158a26
...
...
@@ -5,10 +5,10 @@ var functions = require('./functions');
var
os
=
require
(
'os'
);
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'
)
.
option
(
'id'
,
'
[필수] 학번을 입력합니다.
'
)
.
option
(
'pw'
,
'
[필수] 비밀번호를 입력합니다. 절대 악용되지 않습니다.
'
)
.
option
(
'lectureBefore'
,
'
[선택] 몇번째 전 강좌의 자료를 다운받을지 선택합니다. Default 는 0 입니다.
'
)
.
option
(
'downloadPath'
,
'
[선택] 자료를 다운받을 경로를 선택합니다.'
);
const
flags
=
args
.
parse
(
process
.
argv
);
...
...
@@ -28,29 +28,10 @@ functions.login(flags.id, flags.pw)
.
then
(
functions
.
getClassPageBody
)
.
then
(
functions
.
findFiles
)
.
then
(
function
(
fileArr
)
{
var
lectureBefore
;
if
(
!
flags
.
lectureBefore
)
{
lectureBefore
=
0
;
}
else
{
lectureBefore
=
flags
.
lectureBefore
;
}
return
functions
.
getSelectedFiles
(
fileArr
,
lectureBefore
);
return
functions
.
getSelectedFiles
(
fileArr
,
flags
.
lectureBefore
);
})
.
then
(
function
(
selectedFile
)
{
var
path
;
if
(
!
flags
.
downloadPath
)
{
path
=
os
.
homedir
()
+
'/downloads/klasFileDownloader'
}
else
{
path
=
flags
.
downloadPath
;
}
//
// if (path[path.length - 1] === '/') {
// path = path.substr(0, path.length - 1);
// }
functions
.
downloadSelectedFile
(
selectedFile
,
path
)
functions
.
downloadSelectedFile
(
selectedFile
,
flags
.
downloadPath
);
})
.
catch
(
function
(
err
)
{
console
.
log
(
err
);
...
...
Please
register
or
login
to post a comment