Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
RIT_Project1
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
박권수
2021-05-05 18:44:12 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3538eec4418170aa7580bf7c397d74d7f59b24d2
3538eec4
1 parent
a628adf0
feat. Hide secret key
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
13 deletions
server/src/lib/UpdatingMedicineInfo.js
server/src/lib/UpdatingMedicineInfo.js
View file @
3538eec
const
axios
=
require
(
'axios'
);
const
SERVICE_KEY
=
"tNd%2FZ0MMJA5NZrU9nA5IVTKkhpz6N3j1OGpFT0PmbcCOVEZbpR9PYiNHuD9rLuSsyMWkTXPqHsHLWoxlW%2BVVrg%3D%3D"
const
url
=
"http://apis.data.go.kr/1471000/DrbEasyDrugInfoService/getDrbEasyDrugList"
;
const
updateMedicineInfo
=
async
()
=>
{
const
queryParams
=
'?'
+
encodeURIComponent
(
'ServiceKey'
)
+
'='
+
SERVICE_KEY
;
const
pageNum36
=
'&'
+
encodeURIComponent
(
'pageNo'
)
+
'='
+
encodeURIComponent
(
1
)
const
pageNum37
=
'&'
+
encodeURIComponent
(
'pageNo'
)
+
'='
+
encodeURIComponent
(
2
);
const
numOfItem
=
'&'
+
encodeURIComponent
(
'numOfRows'
)
+
'='
+
encodeURIComponent
(
2
);
exports
.
updateMedicineInfo
=
async
()
=>
{
console
.
log
(
'starting'
)
const
itemArray
=
await
getItemsList
(
getQueryURL
);
await
exportJsonData
(
itemArray
);
console
.
log
(
'data is saved'
);
}
//queryUrl을 return하는 함수 : 한 페이지에 100개의 item씩 요청할 수 있다.
const
getQueryURL
=
(
i
)
=>
{
const
url
=
"http://apis.data.go.kr/1471000/DrbEasyDrugInfoService/getDrbEasyDrugList"
;
const
queryParams
=
'?'
+
encodeURIComponent
(
'ServiceKey'
)
+
'='
+
process
.
env
.
SERVICE_KEY
;
const
pageNum
=
'&'
+
encodeURIComponent
(
'pageNo'
)
+
'='
+
encodeURIComponent
(
i
);
const
numOfItem
=
'&'
+
encodeURIComponent
(
'numOfRows'
)
+
'='
+
encodeURIComponent
(
100
);
const
output
=
'&'
+
encodeURIComponent
(
'type'
)
+
'='
+
encodeURIComponent
(
'json'
);
const
result36
=
await
axios
.
get
(
url
+
queryParams
+
pageNum36
+
numOfItem
+
output
);
const
result37
=
await
axios
.
get
(
url
+
queryParams
+
pageNum37
+
numOfItem
+
output
);
return
url
+
queryParams
+
pageNum
+
numOfItem
+
output
;
}
//모든 page의 item을 list에 push해서 return하는 함수
const
getItemsList
=
async
(
queryUrl
)
=>
{
let
i
=
1
,
getItem
=
null
,
items
=
null
;
const
result
=
new
Array
();
while
(
true
)
{
getItem
=
await
axios
.
get
(
queryUrl
(
i
));
items
=
getItem
.
data
.
body
.
items
;
console
.
log
(
result36
.
data
.
body
.
items
);
console
.
log
(
result37
.
data
.
body
.
items
);
if
(
items
===
undefined
)
return
result
;
result
.
push
(...
items
);
console
.
log
(
'medicine data getting processing... : page'
,
i
,
'done'
);
i
++
;
}
}
updateMedicineInfo
();
\ No newline at end of file
//itemArray에 있는 모든 data를 json으로 만들어서 json파일로 저장
const
exportJsonData
=
async
(
itemList
)
=>
{
itemList
.
forEach
(
item
=>
{
})
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment