신원형

bug fix e-campus login

...@@ -40,17 +40,17 @@ ex) ...@@ -40,17 +40,17 @@ ex)
40 */ 40 */
41 41
42 async function get_schedule(id, pw, target_date) { 42 async function get_schedule(id, pw, target_date) {
43 - return await using_selenium( async (driver) => { 43 + console.log("entered get_schedule_then")
44 + const result = await using_selenium( async (driver) => {
45 + console.log("entered using_selenium_then")
44 return await login(driver, id, pw) 46 return await login(driver, id, pw)
45 .then(async () => { 47 .then(async () => {
48 + console.log("entered login_then")
46 return await load(driver, target_date) 49 return await load(driver, target_date)
47 - .then((data) => {
48 - //logout(driver)
49 - console.log(data)
50 - return data
51 - })
52 }) 50 })
53 }) 51 })
52 +
53 + return await result
54 } 54 }
55 55
56 async function using_selenium(next) { 56 async function using_selenium(next) {
...@@ -62,9 +62,13 @@ async function using_selenium(next) { ...@@ -62,9 +62,13 @@ async function using_selenium(next) {
62 .setFirefoxOptions(option) 62 .setFirefoxOptions(option)
63 .build() 63 .build()
64 64
65 - next(driver).finally(() => { 65 +
66 - driver.quit() 66 + const result = next(driver)
67 - }) 67 +
68 + return await result
69 + //await next(driver).finally(() => {
70 + // driver.quit()
71 + //})
68 } 72 }
69 73
70 async function login(driver, id, pw) { 74 async function login(driver, id, pw) {
......
...@@ -72,10 +72,10 @@ function sendLocation(replyToken, latitude, longitude, locationAdd, locationName ...@@ -72,10 +72,10 @@ function sendLocation(replyToken, latitude, longitude, locationAdd, locationName
72 }); 72 });
73 } 73 }
74 74
75 -function filter_date(date, id, pw) { 75 +async function filter_date(date, id, pw) {
76 - //const schedule = 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 + const first_todo = selector.is_possible_schedule(date, schedule)
78 - const first_todo = false 78 + //const first_todo = false
79 if (first_todo) { 79 if (first_todo) {
80 return `제출되지 않은 과제가 있습니다. ${first_todo}` 80 return `제출되지 않은 과제가 있습니다. ${first_todo}`
81 } 81 }
...@@ -84,6 +84,7 @@ function filter_date(date, id, pw) { ...@@ -84,6 +84,7 @@ function filter_date(date, id, pw) {
84 } 84 }
85 85
86 function is_good_weather(weather_data) { 86 function is_good_weather(weather_data) {
87 + console.log("current weather is :" + weather_data.weather[0].id)
87 if(weather_data.id < 800) { 88 if(weather_data.id < 800) {
88 return false 89 return false
89 } 90 }
...@@ -177,13 +178,13 @@ app.post('/hook', async function (req, res) { ...@@ -177,13 +178,13 @@ app.post('/hook', async function (req, res) {
177 if (first == false && eventObj.message.text == "처음") { 178 if (first == false && eventObj.message.text == "처음") {
178 179
179 const today = new Date() 180 const today = new Date()
180 - const filter_result = filter_date(today, id, pw) 181 + const filter_result = await filter_date(today, id, pw)
181 182
182 if (filter_result) { 183 if (filter_result) {
183 sendText(eventObj.replyToken, filter_result) 184 sendText(eventObj.replyToken, filter_result)
184 } 185 }
185 186
186 - const good_weather = (weather.get_weather_current()).then(it => { 187 + const good_weather = await weather.get_weather_current().then(it => {
187 return is_good_weather(it) 188 return is_good_weather(it)
188 }) 189 })
189 if (!good_weather) { 190 if (!good_weather) {
......
...@@ -22,7 +22,7 @@ async function is_possible_schedule(date, assignments) { ...@@ -22,7 +22,7 @@ async function is_possible_schedule(date, assignments) {
22 return current_timestamp > (target_timestamp - ADayForMS) 22 return current_timestamp > (target_timestamp - ADayForMS)
23 }) 23 })
24 24
25 - if(is_disqualified) { 25 + if(is_disqualified.length > 0) {
26 const disq = is_disqualified.at(0) 26 const disq = is_disqualified.at(0)
27 return `${disq.course_name}: ${disq.assignment_name} [${disq.points} 점]` 27 return `${disq.course_name}: ${disq.assignment_name} [${disq.points} 점]`
28 } else { 28 } else {
......
...@@ -9,18 +9,6 @@ const util = require('util') ...@@ -9,18 +9,6 @@ const util = require('util')
9 const assert = require('assert') 9 const assert = require('assert')
10 10
11 mocha.describe('khcanvas', () => { 11 mocha.describe('khcanvas', () => {
12 - mocha.it('opening selenium', async () => {
13 - await canvas.using_selenium(async (driver) => {
14 - await driver.get("http://khuhub.khu.ac.kr");
15 - await driver.getTitle().then( (title) => {
16 - console.log(title);
17 - });
18 - });
19 - })
20 -});
21 -
22 -
23 -mocha.describe('khcanvas', () => {
24 mocha.it('get schedule', async () => { 12 mocha.it('get schedule', async () => {
25 const rl = rd.createInterface({ 13 const rl = rd.createInterface({
26 input: process.stdin, 14 input: process.stdin,
...@@ -29,13 +17,15 @@ mocha.describe('khcanvas', () => { ...@@ -29,13 +17,15 @@ mocha.describe('khcanvas', () => {
29 17
30 const question = util.promisify(rl.question).bind(rl); 18 const question = util.promisify(rl.question).bind(rl);
31 19
32 - const a = await question('a'); 20 + const fs = require('fs');
33 - const b = await question('b'); 21 + const tokens = JSON.parse(fs.readFileSync("setting.json"))
22 + const a = tokens.id
23 + const b = tokens.pw
34 24
35 return await canvas.get_schedule(a, b, new Date()) 25 return await canvas.get_schedule(a, b, new Date())
36 - .then(it => console.log(it)) 26 + .then(it => console.log("log at: " + it))
37 .catch(it => { 27 .catch(it => {
38 - console.log(it) 28 + console.log("log at (2): " + it)
39 assert.rejects(it) 29 assert.rejects(it)
40 }) 30 })
41 }) 31 })
......