category.js
2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var express = require('express');
var router = express.Router();
var request = require('request');
require('dotenv').config();
/* GET home page. */
let GU_CODE;
let ANIMAL_INFO_API_KEY = process.env.ANIMAL_API_KEY;
let user_gu;
let user_latitude;
let user_longitude;
router.get('/hospital', function (req, res) {
let institute_url = 'http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03';
let qs = `?KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}&Type=json`;
request({
url: library_url + qs,
method: 'GET'
}, function (err, response, body) {
if (!err && res.statusCode == 200) {
let library_result = JSON.parse(body);
let librarys = [];
for (let i = 0; i < library_result.Tbggibllbrm[1].row.length; i++) {
library = library_result.Tbggibllbrm[1].row[i];
if (userArea(library, 'REFINE_LOTNO_ADDR', user_target)) {
librarys.push(library);
}
}
library_grade = evalGrade(library_A, 0.5, librarys.length);
request({
url: institute_url + qs,
method: 'GET'
}, function (err, response, body) {
if (!err && res.statusCode == 200) {
let institute_result = JSON.parse(body);
let institutes = [];
for (let i = 0; i < institute_result.TninsttInstutM[1].row.length; i++) {
institute = institute_result.TninsttInstutM[1].row[i];
if (userArea(institute, 'REFINE_LOTNO_ADDR', user_target)) {
institutes.push(institute);
}
}
institute_grade = evalGrade(institute_A, institute_B, institutes);
grade = avgGrade(library_grade, institute_grade);
res.render('result', { category: 'school', librarys: librarys, institutes: institutes, userLocation: userLocation, grade: grade });
}
})
}
})
});