Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신원형
/
study-or-enjoy
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
신원형
2022-05-23 14:13:25 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
fc54f3e74ac3d9967dd6d0a0a0f059ff66b8f915
fc54f3e7
1 parent
58c4e9c1
working at linux
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
100 additions
and
41 deletions
.vscode/launch.json
khcanvas.js
main.js
package-lock.json
package.json
test/khcanvas_test.js
.vscode/launch.json
View file @
fc54f3e
...
...
@@ -5,6 +5,23 @@
"version"
:
"0.2.0"
,
"configurations"
:
[
{
"type"
:
"node"
,
"request"
:
"launch"
,
"name"
:
"Mocha All"
,
"program"
:
"${workspaceFolder}/node_modules/mocha/bin/_mocha"
,
"args"
:
[
"--timeout"
,
"999999"
,
"--colors"
,
"${workspaceFolder}/test"
],
"console"
:
"integratedTerminal"
,
"internalConsoleOptions"
:
"neverOpen"
,
"skipFiles"
:
[
"<node_internals>/**/*.js"
]
},
{
"type"
:
"pwa-node"
,
"request"
:
"launch"
,
"name"
:
"Launch Program"
,
...
...
khcanvas.js
View file @
fc54f3e
...
...
@@ -40,33 +40,45 @@ ex)
*/
export
async
function
get_schedule
(
id
,
pw
,
target_date
)
{
login
(
id
,
pw
).
then
(
async
driver
=>
{
load
(
driver
,
target_date
)
.
then
(
it
=>
{
console
.
log
(
it
)
logout
(
driver
)
})
return
using_selenium
((
driver
)
=>
{
return
login
(
driver
,
id
,
pw
)
.
then
(()
=>
{
return
load
(
driver
,
target_date
)
.
then
((
data
)
=>
{
//logout(driver)
console
.
log
(
data
)
return
data
})
})
})
}
export
async
function
login
(
id
,
pw
)
{
export
async
function
using_selenium
(
next
)
{
const
option
=
new
firefox
.
Options
()
option
.
setBinary
(
'C:\\Program Files\\Mozilla Firefox\\firefox.exe'
)
option
.
addArguments
(
"-headless"
);
const
driver
=
new
selenium
.
Builder
()
.
forBrowser
(
'firefox'
)
.
setFirefoxOptions
(
option
)
.
build
()
next
(
driver
).
finally
(()
=>
{
driver
.
quit
()
})
}
export
async
function
login
(
driver
,
id
,
pw
)
{
await
driver
.
get
(
"https://khcanvas.khu.ac.kr/"
)
const
idInput
=
await
driver
.
findElement
(
selenium
.
By
.
xpath
(
'//*[@id="login_user_id"]'
));
const
pwInput
=
await
driver
.
findElement
(
selenium
.
By
.
xpath
(
'//*[@id="login_user_password"]'
));
const
login_button
=
await
driver
.
findElement
(
selenium
.
By
.
xpath
(
'//*[@id="form1"]/div/div[3]'
));
await
idInput
.
sendKeys
(
id
);
await
pwInput
.
sendKeys
(
pw
);
await
login_button
.
click
();
return
driver
}
...
...
@@ -76,7 +88,7 @@ export async function load(driver, until) {
await
driver
.
get
(
`https://khcanvas.khu.ac.kr/api/v1/planner/items?start_date=
${
start_date
}
`
);
await
sleep
(
1000
)
await
driver
.
findElement
(
selenium
.
By
.
xpath
(
'/html/body/div/div/nav/ul/li[2]'
)).
click
();
const
data
=
await
driver
.
findElement
(
selenium
.
By
.
xpath
(
'/html/body/div/div/div/div[2]/div/div/div[2]/pre'
));
const
text
=
JSON
.
parse
((
await
data
.
getText
()).
slice
(
9
))
...
...
main.js
View file @
fc54f3e
import
fs
from
'fs/promises'
import
{
login
,
load
,
logout
}
from
'./khcanvas.js'
;
fs
.
readFile
(
"asdffdsa.txt"
).
then
(
it
=>
{
const
auth
=
it
.
toString
().
split
(
'|'
)
login
(
auth
[
0
],
auth
[
1
]).
then
(
async
driver
=>
{
load
(
driver
,
new
Date
())
.
then
(
it
=>
{
console
.
log
(
it
)
logout
(
driver
)
})
}).
catch
(
err
=>
{
console
.
log
(
err
)
})
})
\ No newline at end of file
...
...
package-lock.json
View file @
fc54f3e
...
...
@@ -9,7 +9,7 @@
"version"
:
"1.0.0"
,
"dependencies"
:
{
"@types/selenium-webdriver"
:
"^4.1.0"
,
"eslint"
:
"^8.1
5
.0"
,
"eslint"
:
"^8.1
6
.0"
,
"mocha"
:
"^10.0.0"
,
"selenium-webdriver"
:
"^4.1.2"
},
...
...
@@ -18,14 +18,14 @@
}
},
"node_modules/@eslint/eslintrc"
:
{
"version"
:
"1.
2.3
"
,
"resolved"
:
"https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.
2.3
.tgz"
,
"integrity"
:
"sha512-
uGo44hIwoLGNyduRpjdEpovcbMdd+Nv7amtmJxnKmI8xj6yd5LncmSwDa5NgX/41lIFJtkjD6YdVfgEzPfJ5UA
=="
,
"version"
:
"1.
3.0
"
,
"resolved"
:
"https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.
3.0
.tgz"
,
"integrity"
:
"sha512-
UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw
=="
,
"dependencies"
:
{
"ajv"
:
"^6.12.4"
,
"debug"
:
"^4.3.2"
,
"espree"
:
"^9.3.2"
,
"globals"
:
"^13.
9
.0"
,
"globals"
:
"^13.
15
.0"
,
"ignore"
:
"^5.2.0"
,
"import-fresh"
:
"^3.2.1"
,
"js-yaml"
:
"^4.1.0"
,
...
...
@@ -439,11 +439,11 @@
}
},
"node_modules/eslint"
:
{
"version"
:
"8.1
5
.0"
,
"resolved"
:
"https://registry.npmjs.org/eslint/-/eslint-8.1
5
.0.tgz"
,
"integrity"
:
"sha512-
GG5USZ1jhCu8HJkzGgeK8/+RGnHaNYZGrGDzUtigK3BsGESW/rs2az23XqE0WVwDxy1VRvvjSSGu5nB0Bu+6S
A=="
,
"version"
:
"8.1
6
.0"
,
"resolved"
:
"https://registry.npmjs.org/eslint/-/eslint-8.1
6
.0.tgz"
,
"integrity"
:
"sha512-
MBndsoXY/PeVTDJeWsYj7kLZ5hQpJOfMYLsF6LicLHQWbRDG19lK5jOix4DPl8yY4SUFcE3txy86OzFLWT+yo
A=="
,
"dependencies"
:
{
"@eslint/eslintrc"
:
"^1.
2.3
"
,
"@eslint/eslintrc"
:
"^1.
3.0
"
,
"@humanwhocodes/config-array"
:
"^0.9.2"
,
"ajv"
:
"^6.10.0"
,
"chalk"
:
"^4.0.0"
,
...
...
@@ -461,7 +461,7 @@
"file-entry-cache"
:
"^6.0.1"
,
"functional-red-black-tree"
:
"^1.0.1"
,
"glob-parent"
:
"^6.0.1"
,
"globals"
:
"^13.
6
.0"
,
"globals"
:
"^13.
15
.0"
,
"ignore"
:
"^5.2.0"
,
"import-fresh"
:
"^3.0.0"
,
"imurmurhash"
:
"^0.1.4"
,
...
...
@@ -1623,14 +1623,14 @@
},
"dependencies"
:
{
"@eslint/eslintrc"
:
{
"version"
:
"1.
2.3
"
,
"resolved"
:
"https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.
2.3
.tgz"
,
"integrity"
:
"sha512-
uGo44hIwoLGNyduRpjdEpovcbMdd+Nv7amtmJxnKmI8xj6yd5LncmSwDa5NgX/41lIFJtkjD6YdVfgEzPfJ5UA
=="
,
"version"
:
"1.
3.0
"
,
"resolved"
:
"https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.
3.0
.tgz"
,
"integrity"
:
"sha512-
UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw
=="
,
"requires"
:
{
"ajv"
:
"^6.12.4"
,
"debug"
:
"^4.3.2"
,
"espree"
:
"^9.3.2"
,
"globals"
:
"^13.
9
.0"
,
"globals"
:
"^13.
15
.0"
,
"ignore"
:
"^5.2.0"
,
"import-fresh"
:
"^3.2.1"
,
"js-yaml"
:
"^4.1.0"
,
...
...
@@ -1943,11 +1943,11 @@
"integrity"
:
"sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA=="
},
"eslint"
:
{
"version"
:
"8.1
5
.0"
,
"resolved"
:
"https://registry.npmjs.org/eslint/-/eslint-8.1
5
.0.tgz"
,
"integrity"
:
"sha512-
GG5USZ1jhCu8HJkzGgeK8/+RGnHaNYZGrGDzUtigK3BsGESW/rs2az23XqE0WVwDxy1VRvvjSSGu5nB0Bu+6S
A=="
,
"version"
:
"8.1
6
.0"
,
"resolved"
:
"https://registry.npmjs.org/eslint/-/eslint-8.1
6
.0.tgz"
,
"integrity"
:
"sha512-
MBndsoXY/PeVTDJeWsYj7kLZ5hQpJOfMYLsF6LicLHQWbRDG19lK5jOix4DPl8yY4SUFcE3txy86OzFLWT+yo
A=="
,
"requires"
:
{
"@eslint/eslintrc"
:
"^1.
2.3
"
,
"@eslint/eslintrc"
:
"^1.
3.0
"
,
"@humanwhocodes/config-array"
:
"^0.9.2"
,
"ajv"
:
"^6.10.0"
,
"chalk"
:
"^4.0.0"
,
...
...
@@ -1965,7 +1965,7 @@
"file-entry-cache"
:
"^6.0.1"
,
"functional-red-black-tree"
:
"^1.0.1"
,
"glob-parent"
:
"^6.0.1"
,
"globals"
:
"^13.
6
.0"
,
"globals"
:
"^13.
15
.0"
,
"ignore"
:
"^5.2.0"
,
"import-fresh"
:
"^3.0.0"
,
"imurmurhash"
:
"^0.1.4"
,
...
...
package.json
View file @
fc54f3e
...
...
@@ -14,7 +14,7 @@
"license"
:
""
,
"dependencies"
:
{
"@types/selenium-webdriver"
:
"^4.1.0"
,
"eslint"
:
"^8.1
5
.0"
,
"eslint"
:
"^8.1
6
.0"
,
"mocha"
:
"^10.0.0"
,
"selenium-webdriver"
:
"^4.1.2"
},
...
...
test/khcanvas_test.js
View file @
fc54f3e
//@ts-check
//https://github.com/gatoona/AWS-Selenium
import
*
as
canvas
from
'../khcanvas.js'
import
*
as
rd
from
'readline'
import
{
assert
}
from
'console'
;
describe
(
'khcanvas'
,
()
=>
{
it
(
'opening selenium'
,
()
=>
{
//this.timeout(1000);
canvas
.
using_selenium
(
async
(
driver
)
=>
{
await
driver
.
get
(
"http://khuhub.khu.ac.kr"
);
await
driver
.
getTitle
().
then
(
function
(
title
)
{
console
.
log
(
title
);
});
});
})
});
describe
(
'khcanvas'
,
()
=>
{
it
(
'get schedule'
,
async
()
=>
{
const
rl
=
rd
.
createInterface
({
input
:
process
.
stdin
,
output
:
process
.
stdout
})
rl
.
question
(
'a'
,
async
(
a
)
=>
{
rl
.
question
(
'b'
,
async
(
b
)
=>
{
await
canvas
.
get_schedule
(
a
,
b
,
new
Date
())
.
then
(
it
=>
{
console
.
log
(
it
)
})
.
catch
(
it
=>
{
console
.
log
(
it
)
throw
new
Error
();
})
})
})
})
});
\ No newline at end of file
...
...
Please
register
or
login
to post a comment