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
4
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
최현영
2020-06-04 23:23:54 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1541ede3c9fe2e528daf285bd5d2cbd9b5b2b757
1541ede3
1 parent
2a087a69
Highway congest function added
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
21 deletions
whereur/app.js
whereur/app.js
View file @
1541ede
...
...
@@ -54,7 +54,7 @@ router.route('/process/mapcctv').get(function(req, res){
function
jsonforecast
(
callback
){
function
jsonforecast
(
callback
){
//교통예보
var
url2
=
'http://data.ex.co.kr/openapi/safeDriving/forecast'
;
var
queryParams2
=
'?'
+
encodeURIComponent
(
'key'
)
+
'=4365330273'
;
/* Service Key*/
queryParams2
+=
'&'
+
encodeURIComponent
(
'type'
)
+
'='
+
encodeURIComponent
(
'json'
);
/* */
...
...
@@ -74,6 +74,25 @@ function jsonforecast(callback){
};
function
jsoncongest
(
callback
){
//교통정체
var
url1
=
'http://data.ex.co.kr/openapi/odtraffic/trafficAmountByCongest'
;
var
queryParams1
=
'?'
+
encodeURIComponent
(
'key'
)
+
'=4365330273'
;
/* Service Key*/
queryParams1
+=
'&'
+
encodeURIComponent
(
'type'
)
+
'='
+
encodeURIComponent
(
'json'
);
/* */
request
({
url
:
url1
+
queryParams1
,
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
);
...
...
@@ -94,7 +113,11 @@ function firstforecast(isforecast){
}
else
if
(
isforecast
==
'2'
){
return
true
;
}
else
{
}
else
if
(
isforecast
==
'3'
){
return
true
;
}
else
{
return
false
;
}
}
...
...
@@ -136,7 +159,14 @@ function isroadnumber(typetext){
}
}
function
inputroadnumber
(
typetext
){
if
(
typetext
.
indexOf
(
"번"
)
>=
0
){
return
true
;
}
else
{
return
false
;
}
}
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
...
...
@@ -147,6 +177,7 @@ app.post('/hook', function (req, res) {
var
isselecttypeforecast
;
var
isfindroad
;
var
istypeforecast
;
var
isinputnumber
;
var
eventObj
=
req
.
body
.
events
[
0
];
var
source
=
eventObj
.
source
;
var
message
=
eventObj
.
message
;
...
...
@@ -183,7 +214,7 @@ app.post('/hook', function (req, res) {
}
else
if
(
message
.
text
==
'3'
){
console
.
log
(
'[request Order] '
,
message
);
//
tieupselect(eventObj);
tieupselect
(
eventObj
);
}
}
...
...
@@ -219,6 +250,12 @@ app.post('/hook', function (req, res) {
}
}
isinputnumber
=
inputroadnumber
(
message
.
text
);
if
(
isinputnumber
==
true
){
roadcongest
(
eventObj
,
message
.
text
);
}
res
.
sendStatus
(
200
);
});
...
...
@@ -433,9 +470,6 @@ function busforecasttoS(eventObj){
function
busforecasttoG
(
eventObj
){
jsonforecast
(
function
(
object
){
var
obj
=
object
;
var
jsonForforecast
=
obj
;
...
...
@@ -607,22 +641,91 @@ function roadnumber(eventObj){
});
}
// var url1 = 'http://data.ex.co.kr/openapi/odtraffic/trafficAmountByCongest';
// var queryParams1 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/
// queryParams1 += '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json'); /* */
function
tieupselect
(
eventObj
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"실시간 고속도로 정체상황 안내를 시작합니다."
},
{
"type"
:
"text"
,
"text"
:
"궁금한 노선번호를 입력해 주세요."
},
{
"type"
:
"text"
,
"text"
:
"예) 100번"
},
{
"type"
:
"text"
,
"text"
:
"반드시 노선번호(숫자)뒤에 '번'을 꼭 입력해주세요."
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
// request({
// url: url1 + queryParams1,
// 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);
// console.log(obj.list[0])
// });
function
roadcongest
(
eventObj
,
msg
){
//jsoncongest의 routeNo는 앞의 세자리가 노선 번호, 마지막 숫자가 제1 중부내륙, 제2 중부내륙 처럼 노선번호는 같으나 노선의 경로가 다른 경우를 나타내며, 혹은 구간구간 개통된 고속도로를 구분지을 때도 구별용으로 사용됨으로 필요가 없음.
jsoncongest
(
function
(
object
){
var
obj
=
object
;
var
jsonForcongest
=
obj
;
var
number
=
msg
.
replace
(
'번'
,
''
).
trim
();
console
.
log
(
number
);
var
roadnumberstring
=
""
;
var
count
=
0
;
if
(
number
.
length
==
1
){
//노선번호가 한자수일 경우, 노선을 찾을 때 두자리 혹은 세자리 번호와 겹칠 수 있으므로.
number
=
"00"
+
number
;
}
else
if
(
number
.
length
==
2
){
number
=
"0"
+
number
;
}
for
(
var
i
=
0
;
i
<
jsonForcongest
.
list
.
length
;
i
++
){
if
(
jsonForcongest
.
list
[
i
].
routeNo
.
indexOf
(
number
)
>=
0
){
count
+=
1
;
roadnumberstring
+=
(
"- 노선이름: "
+
jsonForcongest
.
list
[
i
].
routeName
+
", 정체구간: "
+
jsonForcongest
.
list
[
i
].
conzoneName
+
', 기점종점방향: '
+
jsonForcongest
.
list
[
i
].
updownTypeCode
+
', 교통량: '
+
jsonForcongest
.
list
[
i
].
trafficAmout
+
', 평균속도: '
+
jsonForcongest
.
list
[
i
].
speed
+
" "
);
}
}
if
(
count
==
0
){
roadnumberstring
=
"검색하신 노선에서 발견된 정체구간은 없습니다."
;
}
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
msg
+
' 정체상황은 다음과 같습니다.'
},
{
"type"
:
"text"
,
"text"
:
roadnumberstring
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
});
}
...
...
Please
register
or
login
to post a comment