Showing
2 changed files
with
60 additions
and
22 deletions
... | @@ -9,37 +9,46 @@ app.set('views','./views') | ... | @@ -9,37 +9,46 @@ app.set('views','./views') |
9 | app.set('view engine','pug'); | 9 | app.set('view engine','pug'); |
10 | app.use(express.static('public')); | 10 | app.use(express.static('public')); |
11 | 11 | ||
12 | + | ||
12 | //?page=페이지번호&?perPage=페이지당 데이터수 | 13 | //?page=페이지번호&?perPage=페이지당 데이터수 |
13 | const $base_url = `https://api.odcloud.kr/api/apnmOrg/v1/list`; | 14 | const $base_url = `https://api.odcloud.kr/api/apnmOrg/v1/list`; |
14 | const $key = '4US0H%2BXj%2BmS8IR4YL0%2BUb9H4CcbTr92QxhYULfOEz1DT%2BZaaos4sRfNh6cmAD2Icli862Ysc31%2BaE4pWywDBIA%3D%3D'; | 15 | const $key = '4US0H%2BXj%2BmS8IR4YL0%2BUb9H4CcbTr92QxhYULfOEz1DT%2BZaaos4sRfNh6cmAD2Icli862Ysc31%2BaE4pWywDBIA%3D%3D'; |
15 | - | ||
16 | -//임시 | ||
17 | const $page=1; | 16 | const $page=1; |
18 | -const $perPage=10; | 17 | +const $perPage=30000; |
19 | 18 | ||
20 | -const $api_url = $base_url + '?returnType=XML&serviceKey='+$key+'&page='+$page+'&perPage='+$perPage; | 19 | +const $api_url = $base_url + '?serviceKey='+$key+'&page='+$page+'&perPage='+$perPage; |
21 | console.log($api_url); | 20 | console.log($api_url); |
22 | 21 | ||
22 | +//해당 URL로 요청 | ||
23 | +app.post('/',function(req,res,next){ | ||
24 | + const searchWord = req.body.region; //지역 키워드 | ||
23 | 25 | ||
24 | -app.listen(3000,function(){ | 26 | + request($api_url,function(err,response,body){ |
25 | - console.log('Connected 3000 port!'); | 27 | + if(err) throw err; |
26 | -}); | ||
27 | 28 | ||
28 | -request($api_url,function(err,res,body){ | 29 | + //data부분만 추출 |
29 | - $ = cheerio.load(body); | 30 | + var obj = JSON.parse(body).data; |
30 | - const $infoList = $('item') | 31 | + |
31 | - console.log($infoList.html()); | 32 | + // console.log(obj); |
32 | - console.log($infoList.length); | 33 | + |
33 | - // let name = $infoList.find('orgnm').text(); | 34 | + //검색한 지역 포함한 모든 data 담기 |
34 | - // let location = $infoList.find('orgZipaddr').text(); | 35 | + let searchList = obj.filter(searchList => { |
35 | - // console.log(`기관명: ${name}, 위치: ${location}`); | 36 | + return searchList.orgZipaddr.includes(searchWord); |
36 | -}) | 37 | + }); |
38 | + | ||
39 | + // console.log(searchList); | ||
40 | + | ||
41 | + //result라는 변수에 담아 결과 보내기 | ||
42 | + res.render('main', {result:searchList}); | ||
43 | + }) | ||
37 | 44 | ||
38 | -app.post('/search',function(req,res){ | ||
39 | - res.send('내가 검색한 지역은 ' + req.body.region); | ||
40 | }) | 45 | }) |
41 | 46 | ||
42 | -app.get('/',function(req,res){ | ||
43 | 47 | ||
48 | +app.listen(3000,function(){ | ||
49 | + console.log('Connected 3000 port!'); | ||
50 | +}); | ||
51 | + | ||
52 | +app.get('/',function(req,res){ | ||
44 | res.render('main'); | 53 | res.render('main'); |
45 | }) | 54 | }) |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -2,8 +2,37 @@ html | ... | @@ -2,8 +2,37 @@ html |
2 | head | 2 | head |
3 | meta(charset='utf-8') | 3 | meta(charset='utf-8') |
4 | body | 4 | body |
5 | - form(action='/search' method="post") | 5 | + h1 COVID-19 의료기관 검색하기 |
6 | - p | 6 | + |
7 | - input(type='text' name='region' placeholder='지역') | 7 | + form(action='/' method="post") |
8 | p | 8 | p |
9 | + input(type='text' name='region' placeholder='서울시') | ||
9 | input(type='submit') | 10 | input(type='submit') |
11 | + | ||
12 | + //result값 있을때만 | ||
13 | + if result!=NULL | ||
14 | + table | ||
15 | + tr | ||
16 | + th 기관명 | ||
17 | + th 기관 전화번호 | ||
18 | + th 기관 주소 | ||
19 | + th 휴무일 여부 | ||
20 | + th 점심 시작시간 | ||
21 | + th 점심 종료시간 | ||
22 | + th 진료 시작기간 | ||
23 | + th 진료 종료시간 | ||
24 | + -for(i=1; i<result.length; i++) | ||
25 | + tr | ||
26 | + td= result[i].orgnm | ||
27 | + td= result[i].orgTlno | ||
28 | + td= result[i].orgZipaddr | ||
29 | + td= result[i].hldyYn | ||
30 | + td= result[i].lunchSttTm | ||
31 | + td= result[i].lunchEndTm | ||
32 | + td= result[i].sttTm | ||
33 | + td= result[i].endTm | ||
34 | + | ||
35 | + | ||
36 | + | ||
37 | + | ||
38 | + | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment