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-20 23:42:14 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a4fd01bf302499003b2715b02da1da7bca467966
a4fd01bf
1 parent
65c8ee21
initial login feature (using selenium)
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
0 deletions
khcanvas.js
khcanvas.js
0 → 100644
View file @
a4fd01b
import
*
as
selenium
from
'selenium-webdriver'
;
import
*
as
firefox
from
'selenium-webdriver/firefox.js'
/*
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) })
})
*/
/*
open selenium session -> login -> get schedule -> logout -> close selenium session
id: string
pw: string
target_date: Date
returns unsubmitted assignments
ex)
[
{
'course_name': '오픈소스SW개발 00분반'
'due_date': '2022-05-15T14:59:59Z'
'assignment_name': '과제이름'
'points': 10.0
}
]
*/
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
)
})
})
}
export
async
function
login
(
id
,
pw
)
{
const
option
=
new
firefox
.
Options
()
option
.
setBinary
(
'C:\\Program Files\\Mozilla Firefox\\firefox.exe'
)
const
driver
=
new
selenium
.
Builder
()
.
forBrowser
(
'firefox'
)
.
setFirefoxOptions
(
option
)
.
build
()
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
}
export
async
function
load
(
driver
,
until
)
{
const
start_date
=
until
.
toISOString
()
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
))
return
text
.
filter
(
it
=>
!
it
.
submissions
.
submitted
&&
it
.
plannable_type
===
"assignment"
).
map
(
it
=>
new
Map
([[
'course_name'
,
it
.
context_name
],
[
'due_date'
,
it
.
plannable
.
due_at
],
[
'assignment_name'
,
it
.
plannable
.
title
],
[
'points'
,
it
.
plannable
.
points_possible
]]))
}
export
async
function
logout
(
driver
)
{
await
driver
.
get
(
"https://khcanvas.khu.ac.kr/"
)
const
logoutPanel
=
await
driver
.
findElement
(
selenium
.
By
.
xpath
(
'html/body/div[2]/header[2]/div[1]/ul/li[1]/button/div[1]'
)).
click
();
await
sleep
(
1000
)
const
logout
=
await
driver
.
findElement
(
selenium
.
By
.
xpath
(
'html/body/div[3]/span/span/div/div/div/div/div/span/form/button'
));
logout
.
click
()
await
sleep
(
1000
)
driver
.
quit
()
}
function
sleep
(
ms
)
{
return
new
Promise
((
r
)
=>
setTimeout
(
r
,
ms
));
}
\ No newline at end of file
Please
register
or
login
to post a comment