FrontEnd 공공데이터활용지원센터_보건복지부 코로나19 감염 현황

공공데이터활용지원센터_보건복지부 코로나19 감염 현황

예전에 공공데이터 관련해서 크롤링해야흔 부분이 있었는데 node.js로 바로 크롤링한 데이터를 react로 전송했던 부분이 있어 코드를 공유하고자한다.

const getBreeds = async () => {
var url = 'http://openapi.data.go.kr/openapi/service/rest/Covid19/getCovid19InfStateJson';
var queryParams = '?' + encodeURIComponent('ServiceKey') + '=zWJGWsZTX%2FrJP6gryI%2FZZCnS23KP%2FaPF7IzFwYJlTUCKgq2AG3zkalo64Vc5Suf%2FUHoKciZw0dByIBDcP1WR%2Fg%3D%3D'; /* Service Key*/
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('10'); /* */
queryParams += '&' + encodeURIComponent('startCreateDt') + '=' + encodeURIComponent('20200310'); /* */
queryParams += '&' + encodeURIComponent('endCreateDt') + '=' + encodeURIComponent('20200315'); /* */
queryParams += '&' + encodeURIComponent('SEQ') + '=' + encodeURIComponent('30'); /* */
request({
url: url+queryParams,
method: 'GET'
}, function (error, response, body) {
//console.log('Status', response.statusCode);
//console.log('Headers', JSON.stringify(response.headers));
var result = body
var xmlToJson = convert.xml2json(result, {compact: true, spaces: 4});
var Json_result = xmlToJson
//console.log(`xml to json => ${xmlToJson}`)
console.log(`xml to json => ${xmlToJson.body}`)
const json = JSON.parse(parser.toJson(result))
const item = json.response.body.items.item[0]
console.log(item)
// console.table(item)
// const addrs = item.map(i => i.addr)
// const template = `l
// each addr in addrs
// li= addr
// `
// const html = pug.render(template, { addrs: addrs })
// console.log(html)
});
};
router.get('/data', function (req, res, next) {
getBreeds()
});
module.exports = router;

Leave a Reply

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

Related Post

[REACT] .env 를 이용한 변수선언 및 사용법[REACT] .env 를 이용한 변수선언 및 사용법

ENV란? .env 파일 외부 파일(.env)에 환경변수를 정의하여 변수로 받아오는 이유는 보안과 유지보수에 용이하기 때문이다. .env 파일은 프로젝트의 최상위 루트에 파일을 만들어놓는다. 변수명은 반드시 ‘REACT_APP­_‘으로 시작되어야한다. create-react-app에서는 보안이 필요한 환경변수의 유출을

React 프로젝트 구조와 폴더 설명React 프로젝트 구조와 폴더 설명

React는 효율적인 UI 개발을 지원하는 강력한 라이브러리입니다. React 프로젝트를 체계적으로 관리하기 위해 적절한 폴더 구조를 설계하는 것은 매우 중요합니다. 이번 글에서는 React 프로젝트의 기본 구조와 주요 폴더의 역할에 대해 자세히