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-06-06 13:12:42 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ba1dd83cf391ae55cf9953398a8e2b3d200d84d9
ba1dd83c
1 parent
973af2d4
fix login
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
16 deletions
khcanvas.js
main.js
schedule_selector.js
test/khcanvas_test.js
test/selector_test.js
khcanvas.js
View file @
ba1dd83
...
...
@@ -41,7 +41,7 @@ ex)
async
function
get_schedule
(
id
,
pw
,
target_date
)
{
console
.
log
(
"entered get_schedule_then"
)
const
result
=
await
using_selenium
(
async
(
driver
)
=>
{
const
result
=
await
using_selenium
(
async
(
driver
)
=>
{
console
.
log
(
"entered using_selenium_then"
)
return
await
login
(
driver
,
id
,
pw
)
.
then
(
async
()
=>
{
...
...
@@ -95,21 +95,28 @@ async function load(driver, until) {
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
))
logout
(
driver
)
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
]]))
((
!
it
.
submissions
.
submitted
)
&&
(
!
it
.
submissions
.
graded
))
&&
it
.
plannable_type
===
"assignment"
).
map
(
it
=>
{
return
{
"course_name"
:
it
.
context_name
,
"due_date"
:
it
.
plannable
.
due_at
,
"assignment_name"
:
it
.
plannable
.
title
,
"points"
:
it
.
plannable
.
points_possible
}
})
}
async
function
logout
(
driver
)
{
await
driver
.
get
(
"https://khcanvas.khu.ac.kr/"
)
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
)
// await driver.get("https://khcanvas.khu.ac.kr/")
// 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
()
console
.
log
(
"quit"
)
}
function
sleep
(
ms
)
{
...
...
main.js
View file @
ba1dd83
...
...
@@ -74,7 +74,9 @@ function sendLocation(replyToken, latitude, longitude, locationAdd, locationName
async
function
filter_date
(
date
,
id
,
pw
)
{
const
schedule
=
await
canvas
.
get_schedule
(
id
,
pw
,
date
)
const
first_todo
=
selector
.
is_possible_schedule
(
date
,
schedule
)
console
.
log
(
schedule
)
const
first_todo
=
await
selector
.
is_possible_schedule
(
date
,
schedule
)
//const first_todo = false
if
(
first_todo
)
{
return
`제출되지 않은 과제가 있습니다.
${
first_todo
}
`
...
...
schedule_selector.js
View file @
ba1dd83
...
...
@@ -14,17 +14,19 @@
const
ADayForMS
=
1000
*
60
*
60
*
24
async
function
is_possible_schedule
(
date
,
assignments
)
{
const
assignments_dates
=
assignments
.
map
(
it
=>
new
Date
(
it
.
due_date
)
)
const
assignments_dates
=
assignments
.
map
(
it
=>
[
new
Date
(
it
.
due_date
),
it
]
)
const
is_disqualified
=
assignments_dates
.
filter
(
it
=>
{
const
current_timestamp
=
date
.
getTime
()
const
target_timestamp
=
it
.
getTime
()
const
target_timestamp
=
it
[
0
]
.
getTime
()
return
current_timestamp
>
(
target_timestamp
-
ADayForMS
)
return
current_timestamp
>
(
target_timestamp
-
ADayForMS
*
2
)
})
console
.
log
(
is_disqualified
)
if
(
is_disqualified
.
length
>
0
)
{
const
disq
=
is_disqualified
.
at
(
0
)
return
`
${
disq
.
course_name
}
:
${
disq
.
assignment_name
}
[
${
disq
.
points
}
점]`
return
`
${
disq
[
1
].
course_name
}
:
${
disq
[
1
].
assignment_name
}
[
${
disq
[
1
]
.
points
}
점]`
}
else
{
return
null
}
...
...
test/khcanvas_test.js
View file @
ba1dd83
...
...
@@ -23,7 +23,10 @@ mocha.describe('khcanvas', () => {
const
b
=
tokens
.
pw
return
await
canvas
.
get_schedule
(
a
,
b
,
new
Date
())
.
then
(
it
=>
console
.
log
(
"log at: "
+
it
))
.
then
(
it
=>
{
console
.
log
(
"log at: "
)
console
.
log
(
it
)
})
.
catch
(
it
=>
{
console
.
log
(
"log at (2): "
+
it
)
assert
.
rejects
(
it
)
...
...
test/selector_test.js
0 → 100644
View file @
ba1dd83
//@ts-check
//https://github.com/gatoona/AWS-Selenium
const
canvas
=
require
(
'../khcanvas'
)
const
rd
=
require
(
'readline'
)
const
mocha
=
require
(
'mocha'
)
const
process
=
require
(
'node:process'
)
const
util
=
require
(
'util'
)
const
assert
=
require
(
'assert'
)
const
selector
=
require
(
'../schedule_selector'
)
mocha
.
describe
(
'selector'
,
()
=>
{
mocha
.
it
(
'get select'
,
async
()
=>
{
selector
.
is_possible_schedule
(
new
Date
(
"2022-06-07T23:54:59Z"
),
{
size
:
4
,
"course_name"
:
"test"
,
"due_date"
:
"2022-06-08T23:54:59Z"
,
"assignment_name"
:
"test_course"
,
"points"
:
10
})
})
});
\ No newline at end of file
Please
register
or
login
to post a comment