Showing
5 changed files
with
46 additions
and
16 deletions
... | @@ -41,7 +41,7 @@ ex) | ... | @@ -41,7 +41,7 @@ ex) |
41 | 41 | ||
42 | async function get_schedule(id, pw, target_date) { | 42 | async function get_schedule(id, pw, target_date) { |
43 | console.log("entered get_schedule_then") | 43 | console.log("entered get_schedule_then") |
44 | - const result = await using_selenium( async (driver) => { | 44 | + const result = await using_selenium(async (driver) => { |
45 | console.log("entered using_selenium_then") | 45 | console.log("entered using_selenium_then") |
46 | return await login(driver, id, pw) | 46 | return await login(driver, id, pw) |
47 | .then(async () => { | 47 | .then(async () => { |
... | @@ -95,21 +95,28 @@ async function load(driver, until) { | ... | @@ -95,21 +95,28 @@ async function load(driver, until) { |
95 | 95 | ||
96 | const data = await driver.findElement(selenium.By.xpath('/html/body/div/div/div/div[2]/div/div/div[2]/pre')); | 96 | const data = await driver.findElement(selenium.By.xpath('/html/body/div/div/div/div[2]/div/div/div[2]/pre')); |
97 | const text = JSON.parse((await data.getText()).slice(9)) | 97 | const text = JSON.parse((await data.getText()).slice(9)) |
98 | - | 98 | + logout(driver) |
99 | return text.filter(it => | 99 | return text.filter(it => |
100 | - !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]])) | 100 | + ((!it.submissions.submitted) && (!it.submissions.graded)) && it.plannable_type === "assignment").map(it => { |
101 | + return { | ||
102 | + "course_name": it.context_name, | ||
103 | + "due_date": it.plannable.due_at, | ||
104 | + "assignment_name": it.plannable.title, | ||
105 | + "points": it.plannable.points_possible | ||
106 | + } | ||
107 | + }) | ||
101 | } | 108 | } |
102 | 109 | ||
103 | async function logout(driver) { | 110 | async function logout(driver) { |
104 | - await driver.get("https://khcanvas.khu.ac.kr/") | 111 | + // await driver.get("https://khcanvas.khu.ac.kr/") |
105 | - | ||
106 | - await driver.findElement(selenium.By.xpath('html/body/div[2]/header[2]/div[1]/ul/li[1]/button/div[1]')).click(); | ||
107 | - await sleep(1000) | ||
108 | - const logout = await driver.findElement(selenium.By.xpath('html/body/div[3]/span/span/div/div/div/div/div/span/form/button')); | ||
109 | - logout.click() | ||
110 | - await sleep(1000) | ||
111 | 112 | ||
113 | + // await driver.findElement(selenium.By.xpath('html/body/div[2]/header[2]/div[1]/ul/li[1]/button/div[1]')).click(); | ||
114 | + // await sleep(1000) | ||
115 | + // const logout = await driver.findElement(selenium.By.xpath('html/body/div[3]/span/span/div/div/div/div/div/span/form/button')); | ||
116 | + // logout.click() | ||
117 | + // await sleep(1000) | ||
112 | driver.quit() | 118 | driver.quit() |
119 | + console.log("quit") | ||
113 | } | 120 | } |
114 | 121 | ||
115 | function sleep(ms) { | 122 | function sleep(ms) { | ... | ... |
... | @@ -74,7 +74,9 @@ function sendLocation(replyToken, latitude, longitude, locationAdd, locationName | ... | @@ -74,7 +74,9 @@ function sendLocation(replyToken, latitude, longitude, locationAdd, locationName |
74 | 74 | ||
75 | async function filter_date(date, id, pw) { | 75 | async function filter_date(date, id, pw) { |
76 | const schedule = await canvas.get_schedule(id, pw, date) | 76 | const schedule = await canvas.get_schedule(id, pw, date) |
77 | - const first_todo = selector.is_possible_schedule(date, schedule) | 77 | + console.log(schedule) |
78 | + const first_todo = await selector.is_possible_schedule(date, schedule) | ||
79 | + | ||
78 | //const first_todo = false | 80 | //const first_todo = false |
79 | if (first_todo) { | 81 | if (first_todo) { |
80 | return `제출되지 않은 과제가 있습니다. ${first_todo}` | 82 | return `제출되지 않은 과제가 있습니다. ${first_todo}` | ... | ... |
... | @@ -14,17 +14,19 @@ | ... | @@ -14,17 +14,19 @@ |
14 | const ADayForMS = 1000 * 60 * 60 * 24 | 14 | const ADayForMS = 1000 * 60 * 60 * 24 |
15 | 15 | ||
16 | async function is_possible_schedule(date, assignments) { | 16 | async function is_possible_schedule(date, assignments) { |
17 | - const assignments_dates = assignments.map(it => new Date(it.due_date)) | 17 | + const assignments_dates = assignments.map(it => [new Date(it.due_date), it]) |
18 | const is_disqualified = assignments_dates.filter(it => { | 18 | const is_disqualified = assignments_dates.filter(it => { |
19 | const current_timestamp = date.getTime() | 19 | const current_timestamp = date.getTime() |
20 | - const target_timestamp = it.getTime() | 20 | + const target_timestamp = it[0].getTime() |
21 | 21 | ||
22 | - return current_timestamp > (target_timestamp - ADayForMS) | 22 | + return current_timestamp > (target_timestamp - ADayForMS * 2) |
23 | }) | 23 | }) |
24 | 24 | ||
25 | + console.log(is_disqualified) | ||
26 | + | ||
25 | if(is_disqualified.length > 0) { | 27 | if(is_disqualified.length > 0) { |
26 | const disq = is_disqualified.at(0) | 28 | const disq = is_disqualified.at(0) |
27 | - return `${disq.course_name}: ${disq.assignment_name} [${disq.points} 점]` | 29 | + return `${disq[1].course_name}: ${disq[1].assignment_name} [${disq[1].points} 점]` |
28 | } else { | 30 | } else { |
29 | return null | 31 | return null |
30 | } | 32 | } | ... | ... |
... | @@ -23,7 +23,10 @@ mocha.describe('khcanvas', () => { | ... | @@ -23,7 +23,10 @@ mocha.describe('khcanvas', () => { |
23 | const b = tokens.pw | 23 | const b = tokens.pw |
24 | 24 | ||
25 | return await canvas.get_schedule(a, b, new Date()) | 25 | return await canvas.get_schedule(a, b, new Date()) |
26 | - .then(it => console.log("log at: " + it)) | 26 | + .then(it => { |
27 | + console.log("log at: ") | ||
28 | + console.log(it) | ||
29 | + }) | ||
27 | .catch(it => { | 30 | .catch(it => { |
28 | console.log("log at (2): " + it) | 31 | console.log("log at (2): " + it) |
29 | assert.rejects(it) | 32 | assert.rejects(it) | ... | ... |
test/selector_test.js
0 → 100644
1 | +//@ts-check | ||
2 | +//https://github.com/gatoona/AWS-Selenium | ||
3 | + | ||
4 | +const canvas = require('../khcanvas') | ||
5 | +const rd = require('readline') | ||
6 | +const mocha = require('mocha') | ||
7 | +const process = require('node:process') | ||
8 | +const util = require('util') | ||
9 | +const assert = require('assert') | ||
10 | +const selector = require('../schedule_selector') | ||
11 | + | ||
12 | +mocha.describe('selector', () => { | ||
13 | + mocha.it('get select', async () => { | ||
14 | + 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}) | ||
15 | + }) | ||
16 | +}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment