Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김원진
/
Expresswayinfo24
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
최현영
2020-06-13 22:27:51 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
327ec211a0a7f11238d840ff6ad609bbcc26b2da
327ec211
1 parent
f95028be
Expressway travel time fo IC to IC is making...
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
182 additions
and
37 deletions
whereur/app.js
whereur/app.js
View file @
327ec21
...
...
@@ -21,7 +21,7 @@ const datafeejson = feebuffer.toString();
const
feedata
=
JSON
.
parse
(
datafeejson
);
console
.
log
(
"Expressfee.json 파일 읽기"
);
const
namebuffer
=
fs
.
r
o
adFileSync
(
'./whereur/ExpressIC.json'
);
const
namebuffer
=
fs
.
r
e
adFileSync
(
'./whereur/ExpressIC.json'
);
const
datanamejson
=
namebuffer
.
toString
();
const
namedata
=
JSON
.
parse
(
datanamejson
);
console
.
log
(
"Expressname.json 파일 열기"
);
...
...
@@ -56,18 +56,6 @@ router.route('/process/maprealtime').get(function(req, res){
});
router
.
route
(
'/process/construction'
).
get
(
function
(
req
,
res
){
console
.
log
(
'process/maprealconstruction 호출됨'
);
res
.
end
();
});
router
.
route
(
'/process/mapcctv'
).
get
(
function
(
req
,
res
){
console
.
log
(
'process/mapcctv 호출됨'
);
res
.
end
();
});
function
jsonforecast
(
callback
){
//교통예보
var
url2
=
'http://data.ex.co.kr/openapi/safeDriving/forecast'
;
var
queryParams2
=
'?'
+
encodeURIComponent
(
'key'
)
+
'=4365330273'
;
/* Service Key*/
...
...
@@ -106,17 +94,26 @@ function jsoncongest(callback){ //교통정체
});
}
function
jsonICtoICtime
(
startICcode
,
endICcode
,
callback
){
var
url3
=
'http://data.ex.co.kr/openapi/trtm/realUnitTrtm'
;
var
queryParams3
=
'?'
+
encodeURIComponent
(
'key'
)
+
'=4365330273'
;
queryParams3
+=
'&'
+
encodeURIComponent
(
'type'
)
+
'='
+
encodeURIComponent
(
'json'
);
queryParams3
+=
'&'
+
encodeURIComponent
(
'iStartUnitCode'
)
+
'='
+
startICcode
+
'&'
+
encodeURIComponent
(
'iEndUnitCode'
)
+
'='
+
endICcode
+
'&'
+
encodeURIComponent
(
'numOfRows'
)
+
'=10'
+
'&'
+
encodeURIComponent
(
'pageNo'
)
+
'=1'
function
nexttext
(
typetext
){
if
(
typetext
==
'다음'
){
return
true
;
}
request
({
url
:
url3
+
queryParams3
,
method
:
'GET'
},
function
(
error
,
response
,
body
)
{
console
.
log
(
'Status'
,
response
.
statusCode
);
console
.
log
(
'Headers'
,
JSON
.
stringify
(
response
.
headers
));
console
.
log
(
'Reponse received'
,
body
);
var
obj
=
JSON
.
parse
(
body
);
console
.
log
(
obj
);
callback
(
obj
);
});
}
app
.
use
(
'/'
,
router
);
...
...
@@ -142,6 +139,9 @@ function firstforecast(isforecast){
else
if
(
isforecast
==
'4'
){
return
true
;
}
else
if
(
isforecast
==
'5'
){
return
true
;
}
else
{
return
false
;
}
...
...
@@ -184,7 +184,7 @@ function isroadnumber(typetext){
}
}
function
is
roadname
(
typetext
){
function
find
roadname
(
typetext
){
if
(
typetext
==
'나들목정보'
){
return
true
;
}
...
...
@@ -193,6 +193,12 @@ function isroadname(typetext){
}
}
function
nexttext
(
typetext
){
if
(
typetext
==
'다음'
){
return
true
;
}
}
function
inputroadnumber
(
typetext
){
if
(
typetext
.
indexOf
(
"번"
)
>=
0
){
...
...
@@ -263,7 +269,13 @@ function wanttoknowfee(typetext){
}
}
function
wanttoknowtime
(
typetext
){
if
(
typetext
.
indexOf
(
","
)
>=
0
){
return
true
;
}
else
{
return
false
;
}
}
...
...
@@ -285,12 +297,11 @@ app.post('/hook', function (req, res) {
var
isfee
;
var
istime
;
// request log
console
.
log
(
'======================'
,
new
Date
()
,
'======================'
);
console
.
log
(
'[request]'
,
req
.
body
);
console
.
log
(
'[request source] '
,
source
);
console
.
log
(
'[request UserId]'
,
source
.
userId
);
console
.
log
(
'[request message]'
,
message
);
console
.
log
(
userroadcongest
[
source
.
userId
]);
...
...
@@ -309,7 +320,7 @@ app.post('/hook', function (req, res) {
roadnumber
(
eventObj
);
}
isroadname
=
is
roadname
(
message
.
text
);
isroadname
=
find
roadname
(
message
.
text
);
if
(
isroadname
==
true
){
console
.
log
(
"나들목 이름을 궁금해 합니다."
);
roadname
(
eventObj
);
...
...
@@ -334,6 +345,10 @@ app.post('/hook', function (req, res) {
console
.
log
(
"[request Order] "
,
message
);
leadfee
(
eventObj
);
}
else
if
(
message
.
text
==
'5'
)
{
console
.
log
(
"[request Order] "
,
message
);
leadtime
(
eventObj
);
}
}
isselecttypeforecast
=
selecttypeforecast
(
message
.
text
);
...
...
@@ -390,12 +405,14 @@ app.post('/hook', function (req, res) {
timelead
(
eventObj
,
message
.
text
);
}
isinputroadname
=
israodnameExist
(
message
.
text
);
if
(
isinputroadname
==
true
){
isinputroadname
(
eventObj
,
message
.
text
);
inputroadname
(
eventObj
,
message
.
text
);
}
res
.
sendStatus
(
200
);
});
...
...
@@ -419,7 +436,7 @@ function helloworld(eventObj){
},
{
"type"
:
"text"
,
"text"
:
"현재 교통 예보가 궁금하시다면 1번을, 실시간 교통혼잡 상황을 보실려면 2번을, 실시간 정체상황을 알고 싶다면 3번을, 교통요금이 궁금하시다면 4번을, 나들목간
평균시간
"
"text"
:
"현재 교통 예보가 궁금하시다면 1번을, 실시간 교통혼잡 상황을 보실려면 2번을, 실시간 정체상황을 알고 싶다면 3번을, 교통요금이 궁금하시다면 4번을, 나들목간
통행평균시간이 궁금하시다면 5번을 눌러주세요.
"
},
{
"type"
:
"text"
,
...
...
@@ -490,6 +507,44 @@ function leadfee(eventObj){
});
}
function
leadtime
(
eventObj
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"나들목(영업소)간 평균 통행시간 안내를 시작합니다."
},
{
"type"
:
"text"
,
"text"
:
"불완전한 서비스입니다. 정보 제공처에서 제공을 안할 수 있습니다. 이점 유의해 주세요."
},
{
"type"
:
"text"
,
"text"
:
"출발하실 나들목(IC)의 이름과 도착하실 나들목(IC)의 이름을 순서대로 적어주세요."
},
{
"type"
:
"text"
,
"text"
:
"예)남안동,서안동"
},
{
"type"
:
"text"
,
"text"
:
"예) 예천,서안동"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
function
findroad
(
eventObj
){
jsonforecast
(
function
(
object
){
...
...
@@ -837,7 +892,7 @@ function roadname(eventObj){
},
{
"type"
:
"text"
,
"te
s
t"
:
"예) 검색:안동"
"te
x
t"
:
"예) 검색:안동"
}
]
}
...
...
@@ -881,17 +936,20 @@ function tieupselect(eventObj){
});
}
function
i
si
nputroadname
(
eventObj
,
msg
){
function
inputroadname
(
eventObj
,
msg
){
var
icnamelist
=
new
Array
();
var
iclist
=
""
;
var
ExpressICnameLength
=
namedata
.
length
;
var
ExpressICnameLength
=
namedata
.
unitLists
.
length
;
var
icnamelist
=
msg
.
split
(
':'
);
var
isthat
=
false
;
var
iscout
=
0
;
var
iscount
=
0
;
console
.
log
(
ExpressICnameLength
);
console
.
log
(
icnamelist
[
1
]);
for
(
var
i
=
0
;
i
<
ExpressICnameLength
;
i
++
){
if
(
namedata
.
unitLists
[
i
].
unitName
.
indexOf
(
icnamelist
[
1
])
>=
0
){
isthat
=
true
;
iclist
=
"#"
+
str
(
iscount
)
+
" "
+
namedata
.
unitLists
[
i
].
unitName
+
" "
;
iscount
+=
1
;
iclist
+=
"#"
+
String
(
iscount
)
+
" "
+
namedata
.
unitLists
[
i
].
unitName
+
" "
;
}
}
...
...
@@ -906,7 +964,7 @@ function isinputroadname(eventObj, msg){
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"검색결과입니다. : "
+
msg
"text"
:
"검색결과입니다. : "
+
iclist
}
]
...
...
@@ -914,8 +972,6 @@ function isinputroadname(eventObj, msg){
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
...
...
@@ -978,7 +1034,7 @@ function roadcongest(eventObj, msg, userid){
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"검색하신 노선에서 발견된 정체량은 총 "
+
str
(
userroadcongestlength
[
userid
])
+
"입니다."
"text"
:
"검색하신 노선에서 발견된 정체량은 총 "
+
String
(
userroadcongestlength
[
userid
])
+
"입니다."
},
{
"type"
:
"text"
,
...
...
@@ -1095,8 +1151,97 @@ function feelead(eventObj, msg){
function
timelead
(
eventObj
,
msg
){
var
isstart
=
false
;
var
isend
=
false
;
var
start
=
""
;
var
end
=
""
;
var
inputoutputIC
=
msg
.
split
(
','
);
inputoutputIC
[
0
].
trim
();
inputoutputIC
[
1
].
trim
();
console
.
log
(
inputoutputIC
[
0
]);
console
.
log
(
inputoutputIC
[
1
]);
var
length
=
namedata
.
unitLists
.
length
;
for
(
var
i
=
0
;
i
<
length
;
i
++
){
if
(
namedata
.
unitName
==
inputoutputIC
[
0
]){
start
=
namedata
.
unitCode
;
isstart
=
true
;
}
if
(
namedata
.
unitName
==
inputoutputIC
[
1
]){
end
=
namedata
.
unitCode
;
isend
=
false
;
}
}
if
(
isstart
==
true
&&
isend
==
true
){
jsonICtoICtime
(
start
,
end
,
function
(
Object
){
var
avgTime
=
new
Array
();
var
ICtimejson
=
Object
;
var
avgTime
=
ICtimejson
.
realUnitTrtmVO
.
timeAvg
.
split
(
'.'
);
if
(
ICtimejson
.
count
>
0
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
ICtimejson
.
realUnitTrtmVO
[
0
].
startUnitNm
+
"나들목에서 "
+
ICtimejson
.
realUnitTrtmVO
[
0
].
endUnitNm
+
"나들목까지 평균 소요시간은 "
+
avg
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
else
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"죄송합니다. 정보가 없습니다."
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
});
}
else
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"일치하는 나들목이 없습니다. 다시 입력해 주세요."
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
}
try
{
...
...
Please
register
or
login
to post a comment