EC2 Default User

feat: Implement bus arrival information output

var express = require('express');
require("dotenv").config();
var url = 'http://apis.data.go.kr/6410000/busarrivalservice/getBusArrivalList';
var queryParams = '?' + encodeURIComponent('serviceKey') + 'Y6FZX1ZGniy+sKjl3AYf+bnh719O0mTDXOdJEODTJ4x1hgFVU60TCHS8Cj//pUtXTkEBp6k2RQ7GGuTqNeAiyA=='; /* Service Key*/
queryParams += '&' + encodeURIComponent('stationId') + '=' + encodeURIComponent('200000078'); /* */
const fs = require('fs');
const path = require('path');
......
var request = require('request');
const convert = require("xml-js")
const convert = require("xml-js");
const { routeIdToBusNum } = require("./routeidmap");
var url = 'http://apis.data.go.kr/6410000/busarrivalservice/getBusArrivalList';
var queryParams = '?' + encodeURIComponent('serviceKey') + process.env.SERVICE_KEY; /* Service Key*/
......@@ -11,11 +12,27 @@ function callRequest() {
url: url + queryParams,
method: 'GET'
}, function (error, response, body) {
const data = convert.xml2js(body, { compact: true }).response.msgBody
if (data)
resolve(JSON.stringify(data.busArrivalList[1]));
else
resolve("운행 중인 버스가 없습니다.");
const data = convert.xml2js(body, { compact: true }).response.msgBody.busArrivalList
if(!data) resolve("운행 중인 버스가 없습니다.");
let result = "";
for (let i in data) {
result += `${routeIdToBusNum[data[i].routeId._text]}번 버스 도착 정보입니다\n`;
result += `첫 번째 도착: ${data[i].predictTime1._text}\n두 번째 도착: ${data[i].predictTime2._text}\n\n`;
}
resolve(result.substring(0, result.length - 2));
// const data1 = convert.xml2js(body, { compact: true }).response.msgBody.busArrivalList[0].predictTime1._text
// const data2 = convert.xml2js(body, { compact: true }).response.msgBody.busArrivalList[0].predictTime2._text
// if (data1)
// {
// //resolve(JSON.stringify(data.busArrivalList[0]));
// console.log("첫 번째: " + data1)
// resolve("첫 번째: " + data1 + "\n두 번째: "+data2);
// //resolve(JSON.stringify(data));
// }
// else
// resolve("운행 중인 버스가 없습니다.");
});
})
}
......
module.exports = {
200000115: "5100",
200000103: "9",
234000016: "1112",
234000001: "5500_1",
200000112: "7000",
234001243: "5107",
routeIdToBusNum: {
200000115: "5100",
200000103: "9",
234000016: "1112",
200000112: "7000",
234000001: "5500_1",
234001243: "5107",
},
busNumToRouteId: {
"5100" : 200000115,
"9" : 200000103,
"1112" : 234000016,
"7000" : 200000112,
"5500_1" : 234000001,
"5107" : 234001243,
}
}
\ No newline at end of file
......