박지환

Update get data array

Showing 1 changed file with 31 additions and 2 deletions
...@@ -14,10 +14,13 @@ var url = ...@@ -14,10 +14,13 @@ var url =
14 "http://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService/" + 14 "http://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService/" +
15 operation; 15 operation;
16 var queryParams = "?" + "solYear" + "=" + "2022"; 16 var queryParams = "?" + "solYear" + "=" + "2022";
17 -queryParams += "&" + "solMonth" + "=" + "05"; 17 +queryParams += "&" + "solMonth" + "=" + "09";
18 queryParams += "&" + "ServiceKey" + "=" + SERVEICE_KEY; 18 queryParams += "&" + "ServiceKey" + "=" + SERVEICE_KEY;
19 let requestUrl = url + queryParams; 19 let requestUrl = url + queryParams;
20 var text = ""; 20 var text = "";
21 +var text2 = "";
22 +var dateName = [];
23 +var locdate = [];
21 24
22 app.get("/", function (req, res) { 25 app.get("/", function (req, res) {
23 request.get(requestUrl, (err, res, body) => { 26 request.get(requestUrl, (err, res, body) => {
...@@ -36,11 +39,37 @@ app.get("/", function (req, res) { ...@@ -36,11 +39,37 @@ app.get("/", function (req, res) {
36 console.log(res); 39 console.log(res);
37 text = JSON.stringify(res); 40 text = JSON.stringify(res);
38 console.log(text); 41 console.log(text);
42 + dateName = [];
43 + var idx = text.indexOf("dateName", 0);
44 + while (idx != -1) {
45 + console.log(idx);
46 + var start = text.indexOf("[", idx) + 2;
47 + var end = text.indexOf("]", idx) - 1;
48 + var tempStr = text.substring(start, end);
49 + console.log(tempStr);
50 + dateName.push(tempStr);
51 + idx = text.indexOf("dateName", idx + 1);
52 + }
53 + console.log(dateName);
54 + locdate = [];
55 + idx = text.indexOf("locdate", 0);
56 + while (idx != -1) {
57 + console.log(idx);
58 + var start = text.indexOf("[", idx) + 2;
59 + var end = text.indexOf("]", idx) - 1;
60 + var tempStr = text.substring(start, end);
61 + console.log(tempStr);
62 + locdate.push(tempStr);
63 + idx = text.indexOf("locdate", idx + 1);
64 + }
65 + console.log(locdate);
66 + text2 = dateName.toString() + "&" + locdate.toString();
39 }); 67 });
40 } 68 }
41 } 69 }
42 }); 70 });
43 - res.send(text); 71 + // res.send(text);
72 + res.send(text2);
44 }); 73 });
45 74
46 const port = 8080; 75 const port = 8080;
......