Toggle navigation
Toggle navigation
This project
Loading...
Sign in
term-project
/
project
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-12-09 17:23:26 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6df2d1b6f38e33e15897336abc6d6377a1a039dc
6df2d1b6
1 parent
6e8b7903
Delete foodapi.js
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
59 deletions
express/foodapi.js
express/foodapi.js
deleted
100644 → 0
View file @
6e8b790
var
express
=
require
(
'express'
);
var
request
=
require
(
'request'
);
//xml을 json으로 바꾼다.
const
convert
=
require
(
'xml-js'
);
var
ProductCategoryName
=
'스위트초콜릿'
;
var
url
=
'http://apis.data.go.kr/1470000/FoodAdtvInfoService/getFoodAdtvInfoList'
;
var
key
=
'ofY2ppOq5kBqT5jYPaGsW%2BEy7OR5a1bf5Z9PHvqNKvwO5DSCaU2x2qCj%2FoXnuB1YVbMTlErkHWSMEsR5b7isrw%3D%3D'
;
var
queryParams
=
'?'
+
encodeURIComponent
(
'ServiceKey'
)
+
'='
+
key
;
//queryParams += '&' + encodeURIComponent('prdlst_cd') + '=' + encodeURIComponent('C0118010300000');
queryParams
+=
'&'
+
encodeURIComponent
(
'pc_kor_nm'
)
+
'='
+
encodeURIComponent
(
ProductCategoryName
);
//queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('213');
//queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('100');
request
({
url
:
url
+
queryParams
,
method
:
'GET'
},
function
(
error
,
response
,
body
)
{
if
(
error
){
console
.
log
(
'에러입니다.'
)
}
else
{
if
(
response
.
statusCode
==
200
){
var
result
=
body
;
var
xmltojson
=
convert
.
xml2json
(
result
,{
compact
:
true
,
spaces
:
4
});
var
resObj
=
eval
(
"("
+
xmltojson
+
")"
);
var
resultItems
=
resObj
.
response
.
body
.
items
;
var
resultLeng
=
Object
.
keys
(
resultItems
);
if
(
Object
.
keys
(
resultItems
).
length
!=
0
){
console
.
log
(
"valid input : 식품 첨가물 정보를 받아옵니다."
);
var
responseMessage
=
'[ '
+
resultItems
.
item
[
0
].
PC_KOR_NM
.
_text
+
' ]\n'
;
//하나의 카테고리에 대한 정보만 받는다고 가정해 반복문 밖으로 뺐습니다.
for
(
var
i
=
0
;
i
<
resultItems
.
item
.
length
;
i
++
)
{
//var responseMessage ='[ ' + resultItems.item[i].PC_KOR_NM._text + ' ]\n';
var
addictive
=
resultItems
.
item
[
i
].
T_KOR_NM
.
_text
;
var
specVal
=
resultItems
.
item
[
i
].
SPEC_VAL_SUMUP
.
_text
;
var
yn
=
resultItems
.
item
[
i
].
INJRY_YN
.
_text
;
responseMessage
+=
addictive
+
' : '
+
specVal
+
'['
+
yn
+
']'
+
'\n'
;
}
}
else
{
console
.
log
(
"Invalid Input : 에러 메시지 전송"
);
var
responseMessage
=
"잘못 된 입력입니다. 라벨의 식품유형을 확인하고 다시 입력해주세요."
;
}
console
.
log
(
'[responese message]'
,
responseMessage
);
}
}
});
Please
register
or
login
to post a comment