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-31 17:03:16 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
eb394bb21b2e30378a11291d9381203c2580e9df
eb394bb2
1 parent
05678cc2
changed to use require()
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
130 additions
and
21 deletions
.eslintrc.json
khcanvas.js
main.js
package.json
schedule_selector.js
talk.js
test/khcanvas_test.js
test/weather_test.js
weather.js
.eslintrc.json
View file @
eb394bb
{
"env"
:
{
"browser"
:
true
,
"node"
:
true
,
"es2021"
:
true
},
"extends"
:
"eslint:recommended"
,
...
...
khcanvas.js
View file @
eb394bb
import
*
as
selenium
from
'selenium-webdriver'
;
import
*
as
firefox
from
'selenium-webdriver/firefox.js'
const
selenium
=
require
(
'selenium-webdriver'
)
const
firefox
=
require
(
'selenium-webdriver/firefox'
)
/*
...
...
@@ -39,7 +39,7 @@ ex)
]
*/
export
async
function
get_schedule
(
id
,
pw
,
target_date
)
{
async
function
get_schedule
(
id
,
pw
,
target_date
)
{
return
await
using_selenium
(
async
(
driver
)
=>
{
return
await
login
(
driver
,
id
,
pw
)
.
then
(
async
()
=>
{
...
...
@@ -53,7 +53,7 @@ export async function get_schedule(id, pw, target_date) {
})
}
export
async
function
using_selenium
(
next
)
{
async
function
using_selenium
(
next
)
{
const
option
=
new
firefox
.
Options
()
option
.
addArguments
(
"-headless"
);
...
...
@@ -67,7 +67,7 @@ export async function using_selenium(next) {
})
}
export
async
function
login
(
driver
,
id
,
pw
)
{
async
function
login
(
driver
,
id
,
pw
)
{
await
driver
.
get
(
"https://khcanvas.khu.ac.kr/"
)
...
...
@@ -82,7 +82,7 @@ export async function login(driver, id, pw) {
return
driver
}
export
async
function
load
(
driver
,
until
)
{
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
}
`
);
...
...
@@ -96,7 +96,7 @@ export async function load(driver, until) {
!
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
)
{
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
();
...
...
@@ -110,4 +110,10 @@ export async function logout(driver) {
function
sleep
(
ms
)
{
return
new
Promise
((
r
)
=>
setTimeout
(
r
,
ms
));
}
\ No newline at end of file
}
module
.
exports
.
get_schedule
=
get_schedule
module
.
exports
.
using_selenium
=
using_selenium
module
.
exports
.
login
=
login
module
.
exports
.
load
=
load
module
.
exports
.
logout
=
logout
\ No newline at end of file
...
...
main.js
View file @
eb394bb
var
express
=
require
(
'express'
);
const
request
=
require
(
'request'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
'채널 토큰으로 변경'
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
const
domain
=
"도메인 변경"
const
sslport
=
23023
;
const
bodyParser
=
require
(
'body-parser'
);
var
app
=
express
();
app
.
use
(
bodyParser
.
json
());
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
var
eventObj
=
req
.
body
.
events
[
0
];
var
source
=
eventObj
.
source
;
var
message
=
eventObj
.
message
;
// request log
console
.
log
(
'======================'
,
new
Date
()
,
'======================'
);
console
.
log
(
'[request]'
,
req
.
body
);
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"Hello, user"
},
{
"type"
:
"text"
,
"text"
:
"May I help you?"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
res
.
sendStatus
(
200
);
});
try
{
const
option
=
{
ca
:
fs
.
readFileSync
(
'/etc/letsencrypt/live/'
+
domain
+
'/fullchain.pem'
),
key
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
domain
+
'/privkey.pem'
),
'utf8'
).
toString
(),
cert
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
domain
+
'/cert.pem'
),
'utf8'
).
toString
(),
};
HTTPS
.
createServer
(
option
,
app
).
listen
(
sslport
,
()
=>
{
console
.
log
(
`[HTTPS] Server is started on port
${
sslport
}
`
);
});
}
catch
(
error
)
{
console
.
log
(
'[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'
);
console
.
log
(
error
);
}
...
...
package.json
View file @
eb394bb
...
...
@@ -19,7 +19,7 @@
"mocha"
:
"^10.0.0"
,
"selenium-webdriver"
:
"^4.1.2"
},
"type"
:
"
module
"
,
"type"
:
"
commonjs
"
,
"devDependencies"
:{
"@types/node"
:
"^17.0.35"
,
"eslint"
:
"^8.16.0"
...
...
schedule_selector.js
0 → 100644
View file @
eb394bb
//@ts-check
/* eslint-disable no-unused-vars */
/*
[
{
'course_name': 'name'
'due_date': '2022-05-15T14:59:59Z'
'assignment_name': '과제이름'
'points': 10.0
}
]
*/
const
ADayForMS
=
1000
*
60
*
60
*
24
export
async
function
is_possible_schedule
(
date
,
assignments
)
{
const
assignments_dates
=
assignments
.
map
(
it
=>
new
Date
(
it
.
due_date
))
const
is_disqualified
=
assignments_dates
.
filter
(
it
=>
{
const
current_timestamp
=
date
.
getTime
()
const
target_timestamp
=
it
.
getTime
()
return
current_timestamp
>
(
target_timestamp
-
ADayForMS
)
})
if
(
is_disqualified
)
{
return
is_disqualified
.
at
(
0
)
}
else
{
return
null
}
}
\ No newline at end of file
talk.js
0 → 100644
View file @
eb394bb
class
Talk
{
}
\ No newline at end of file
test/khcanvas_test.js
View file @
eb394bb
//@ts-check
//https://github.com/gatoona/AWS-Selenium
import
*
as
canvas
from
'../khcanvas.js'
import
*
as
rd
from
'readline'
import
*
as
mocha
from
'mocha'
import
process
from
'node:process'
;
import
util
from
'util'
import
{
rejects
}
from
'assert'
;
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'
)
mocha
.
describe
(
'khcanvas'
,
()
=>
{
mocha
.
it
(
'opening selenium'
,
async
()
=>
{
...
...
@@ -36,7 +36,7 @@ mocha.describe('khcanvas', () => {
.
then
(
it
=>
console
.
log
(
it
))
.
catch
(
it
=>
{
console
.
log
(
it
)
rejects
(
it
)
assert
.
rejects
(
it
)
})
})
});
\ No newline at end of file
...
...
test/weather_test.js
View file @
eb394bb
import
*
as
mocha
from
'mocha'
import
*
as
weater
from
'../weather.js'
const
mocha
=
require
(
'mocha'
)
const
weater
=
require
(
'../weather'
)
mocha
.
describe
(
'weather'
,
()
=>
{
mocha
.
it
(
'get tomorrow weather'
,
async
()
=>
{
...
...
weather.js
View file @
eb394bb
//@ts-check
/* eslint-disable no-unused-vars */
import
*
as
axios
from
'axios'
;
const
axios
=
require
(
'axios'
)
// 최대 7 일간 예보를 반환합니다. 경희대 국제캠퍼스 정문 앞 삼거리 기준으로 호출됩니다.
...
...
@@ -52,7 +52,7 @@ import * as axios from 'axios';
"uvi": 7.71 //The maximum value of UV index for the day
*/
export
async
function
get_weather_forecast
(
date
)
{
async
function
get_weather_forecast
(
date
)
{
const
lat
=
37.24764302276268
//위도
const
lon
=
127.0783992268606
//경도
const
api_key
=
"336ddd01d3d6f78782eed90d3921bc7e"
...
...
@@ -79,4 +79,6 @@ function find_min_index(array) {
}
return
lowest_index
}
\ No newline at end of file
}
module
.
exports
.
get_weather_forecast
=
get_weather_forecast
\ No newline at end of file
...
...
Please
register
or
login
to post a comment