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 19:16:42 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
4f16e9cf3f1cbd2b7a406afc042752ae434d5ed6
4f16e9cf
2 parents
ed4dc171
77ef78f7
modify main.js
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
37 deletions
main.js
talk.js
weather.js
main.js
View file @
4f16e9c
const
express
=
require
(
'express'
);
const
request
=
require
(
'request'
);
const
talk
=
require
(
'./talk'
)
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
const
bodyParser
=
require
(
'body-parser'
);
// var latitude = 37.2429832;
// var longitude = 127.0749535;
// var locationAdd = "경기 용인시 기흥구 서그내로49번길 13"
// var location_name = "카페 서천"
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
tokens
=
JSON
.
parse
(
fs
.
readFileSync
(
"setting.json"
))
const
sslport
=
23023
;
...
...
@@ -25,6 +18,10 @@ var first = false; //첫 시도인지
var
second
=
false
;
//첫번째 분류 선택했는지
var
destCar
=
""
;
var
destination
=
[];
const
canvas
=
require
(
'./khcanvas'
)
const
selector
=
require
(
'./schedule_selector'
)
const
weather
=
require
(
'./weather'
)
function
sendText
(
replyToken
,
messages
)
{
request
.
post
(
...
...
@@ -51,7 +48,7 @@ function sendText(replyToken, messages) {
// OR
// https://developers.line.biz/en/reference/messaging-api/#location-message
function
send
Image
(
replyToken
,
imageUrl
)
{
function
send
Location
(
replyToken
,
latitude
,
longitude
,
locationAdd
,
locationName
)
{
request
.
post
(
{
url
:
TARGET_URL
,
...
...
@@ -75,9 +72,28 @@ function sendImage(replyToken, imageUrl) {
});
}
function
filter_date
(
date
,
id
,
pw
)
{
const
schedule
=
canvas
.
get_schedule
(
id
,
pw
,
date
)
const
first_todo
=
selector
.
is_possible_schedule
(
date
,
schedule
)
if
(
first_todo
)
{
return
`제출되지 않은 과제가 있습니다.
${
first_todo
}
`
}
return
null
}
/*
1. 사용자가 아무 메세지나 입력?
2. 이캠퍼스 일정 찾기
3. 날씨 적절한지 판단
4. 카테고리 물어보기
5. 랜덤 위치를 알려주는 메세지 반환
*/
var
app
=
express
();
app
.
use
(
bodyParser
.
json
());
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
app
.
post
(
'/hook'
,
async
function
(
req
,
res
)
{
var
eventObj
=
req
.
body
.
events
[
0
];
var
source
=
eventObj
.
source
;
...
...
@@ -89,6 +105,17 @@ app.post('/hook', function (req, res) {
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
const
today
=
new
Date
()
const
filter_result
=
filter_date
(
today
,
id
,
pw
)
if
(
filter_result
)
{
sendText
(
eventObj
.
replyToken
,
filter_result
)
}
(
await
weather
.
get_weather_current
()).
then
(
it
=>
{
})
if
(
first
==
false
&&
eventObj
.
message
.
text
==
"처음"
)
{
request
.
post
(
{
...
...
@@ -110,7 +137,6 @@ app.post('/hook', function (req, res) {
});
first
=
true
;
}
else
if
(
first
==
true
&&
second
==
false
)
{
if
(
eventObj
.
message
.
text
==
1
)
{
//식사 선택
...
...
talk.js
View file @
4f16e9c
const
canvas
=
require
(
'./khcanvas'
)
const
selector
=
require
(
'./schedule_selector'
)
function
start
(
id
,
pw
)
{
const
today
=
new
Date
()
const
filter_result
=
filter_date
(
today
,
id
,
pw
)
if
(
filter_result
)
{
return
filter_result
}
}
function
filter_date
(
date
,
id
,
pw
)
{
const
schedule
=
canvas
.
get_schedule
(
id
,
pw
,
date
)
const
first_todo
=
selector
.
is_possible_schedule
(
date
,
schedule
)
if
(
first_todo
)
{
return
`제출되지 않은 과제가 있습니다.
${
first_todo
}
`
}
return
null
}
module
.
exports
.
start
=
start
\ No newline at end of file
weather.js
View file @
4f16e9c
...
...
@@ -10,7 +10,7 @@ const axios = require('axios')
// 예) 6/2일 오후 4시 호출 => 6/2일 정오 날씨 반환 (정오 기준이므로)
// 온도의 경우 단위는 섭씨입니다.
/*example
/*example
- forecast
"dt": 1653620400,
"sunrise": 1653596132,
...
...
@@ -52,6 +52,34 @@ const axios = require('axios')
"uvi": 7.71 //The maximum value of UV index for the day
*/
/*example - current
{
"dt": 1653989440,
"sunrise": 1653941622,
"sunset": 1653993914,
"temp": 23.74,
"feels_like": 22.82,
"pressure": 1008,
"humidity": 25,
"dew_point": 2.56,
"uvi": 0.17,
"clouds": 20,
"visibility": 10000,
"wind_speed": 5.66,
"wind_deg": 300,
"weather": [
{
"id": 801,
"main": "Clouds",
"description": "few clouds",
"icon": "02d"
}
]
}
*/
async
function
get_weather_forecast
(
date
)
{
const
lat
=
37.24764302276268
//위도
const
lon
=
127.0783992268606
//경도
...
...
@@ -62,6 +90,16 @@ async function get_weather_forecast(date) {
return
await
axios
.
default
.
get
(
target
).
then
(
it
=>
{
return
extract_from
(
date
,
it
.
data
)
})
}
async
function
get_weather_current
()
{
const
lat
=
37.24764302276268
//위도
const
lon
=
127.0783992268606
//경도
const
api_key
=
"336ddd01d3d6f78782eed90d3921bc7e"
const
target
=
`https://api.openweathermap.org/data/2.5/onecall?lat=
${
lat
}
&lon=
${
lon
}
&exclude=minutely,hourly,alerts&appid=
${
api_key
}
&units=metric`
return
await
axios
.
default
.
get
(
target
).
then
(
it
=>
{
return
extract_current
(
it
.
data
)
})
}
function
extract_from
(
date
,
json_response
)
{
const
target_timestamp
=
Math
.
floor
(
date
.
getTime
()
/
1000
)
...
...
@@ -70,6 +108,10 @@ function extract_from(date, json_response) {
return
json_response
.
daily
[
target_index
]
}
function
extract_current
(
json_response
)
{
return
json_response
.
current
}
function
find_min_index
(
array
)
{
let
lowest_index
=
0
for
(
var
i
=
0
;
i
<
array
.
length
;
i
++
)
{
...
...
@@ -82,3 +124,4 @@ function find_min_index(array) {
}
module
.
exports
.
get_weather_forecast
=
get_weather_forecast
module
.
exports
.
get_weather_current
=
get_weather_current
\ No newline at end of file
...
...
Please
register
or
login
to post a comment