example api call file add , requesting api part advanced(functionalize)
Showing
3 changed files
with
59 additions
and
24 deletions
lib/example_result.json
0 → 100644
| 1 | +{ | ||
| 2 | + "weather": { | ||
| 3 | + "minutely": [{ | ||
| 4 | + "station": { | ||
| 5 | + "longitude": "127.1164", | ||
| 6 | + "latitude": "37.2772", | ||
| 7 | + "name": "기흥구", | ||
| 8 | + "id": "371", | ||
| 9 | + "type": "KMA" | ||
| 10 | + }, | ||
| 11 | + "wind": { | ||
| 12 | + "wdir": "189.50", | ||
| 13 | + "wspd": "2.20" | ||
| 14 | + }, | ||
| 15 | + "precipitation": { | ||
| 16 | + "sinceOntime": "0.00", | ||
| 17 | + "type": "0" | ||
| 18 | + }, | ||
| 19 | + "sky": { | ||
| 20 | + "code": "SKY_A07", | ||
| 21 | + "name": "흐림" | ||
| 22 | + }, | ||
| 23 | + "rain": { | ||
| 24 | + "sinceOntime": "0.00", | ||
| 25 | + "sinceMidnight": "", | ||
| 26 | + "last10min": "0.00", | ||
| 27 | + "last15min": "0.00", | ||
| 28 | + "last30min": "0.00", | ||
| 29 | + "last1hour": "0.00", | ||
| 30 | + "last6hour": "0.50", | ||
| 31 | + "last12hour": "0.50", | ||
| 32 | + "last24hour": "0.50" | ||
| 33 | + }, | ||
| 34 | + "temperature": { | ||
| 35 | + "tc": "5.90", | ||
| 36 | + "tmax": "7.00", | ||
| 37 | + "tmin": "-1.00" | ||
| 38 | + }, | ||
| 39 | + "humidity": "", | ||
| 40 | + "pressure": { | ||
| 41 | + "surface": "", | ||
| 42 | + "seaLevel": "" | ||
| 43 | + }, | ||
| 44 | + "lightning": "0", | ||
| 45 | + "timeObservation": "2018-12-06 14:14:00" | ||
| 46 | + }] | ||
| 47 | + }, | ||
| 48 | + "common": { | ||
| 49 | + "alertYn": "Y", | ||
| 50 | + "stormYn": "N" | ||
| 51 | + }, | ||
| 52 | + "result": { | ||
| 53 | + "code": 9200, | ||
| 54 | + "requestUrl": "/weather/current/minutely?appKey=key&lat=37.239795&lon=127.083240", | ||
| 55 | + "message": "성공" | ||
| 56 | + } | ||
| 57 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
lib/request_api.js
deleted
100644 → 0
| 1 | -const secret_key = require('../keys/api_option').key; | ||
| 2 | -const requesting = require('request'); | ||
| 3 | - | ||
| 4 | -module.exports = (io) => { | ||
| 5 | - let info = {} | ||
| 6 | - setInterval(() => { | ||
| 7 | - requesting.get({ | ||
| 8 | - // api를 요청할 주소 -- 시크릿키,위도,경도 입력 | ||
| 9 | - url: `https://api2.sktelecom.com/weather/current/minutely?appKey=${secret_key}&lat=37.239795&lon=127.083240`, | ||
| 10 | - json: true | ||
| 11 | - }, | ||
| 12 | - //api에게 응답 받았을때 실행되는 callback func | ||
| 13 | - function (err, api_res, api_body) { | ||
| 14 | - if (err) throw err; | ||
| 15 | - // api의 대답이 있을경우 실행 | ||
| 16 | - if (api_res) { | ||
| 17 | - console.log(api_body); | ||
| 18 | - io.emit("new_info_in", info) // api 호출 정보 클라이언트에게 전송 | ||
| 19 | - } | ||
| 20 | - }); | ||
| 21 | - }, 60 * 1000); //1분마다 호출 | ||
| 22 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -16,16 +16,16 @@ module.exports = (server, app) => { | ... | @@ -16,16 +16,16 @@ module.exports = (server, app) => { |
| 16 | url: `https://api2.sktelecom.com/weather/${when}/${what}?appKey=${secret_key}&lat=${lat}&lon=${lon}`, | 16 | url: `https://api2.sktelecom.com/weather/${when}/${what}?appKey=${secret_key}&lat=${lat}&lon=${lon}`, |
| 17 | json: true | 17 | json: true |
| 18 | }, | 18 | }, |
| 19 | - //api에게 응답 받았을때 실행되는 callback func | 19 | + //api에게 응답 받았을때 실행되는 callback function |
| 20 | function (err, api_res, api_body) { | 20 | function (err, api_res, api_body) { |
| 21 | if (err) throw err; | 21 | if (err) throw err; |
| 22 | // api의 대답이 있을경우 실행 | 22 | // api의 대답이 있을경우 실행 |
| 23 | if (api_res) { | 23 | if (api_res) { |
| 24 | console.log(api_body); | 24 | console.log(api_body); |
| 25 | + // api_body.weather.minutely[0] | ||
| 25 | } | 26 | } |
| 26 | }); | 27 | }); |
| 27 | } | 28 | } |
| 28 | - | ||
| 29 | io.on('connection', (socket) => { //웹 페이지 연결시 루프 동작 | 29 | io.on('connection', (socket) => { //웹 페이지 연결시 루프 동작 |
| 30 | let API_CALL; | 30 | let API_CALL; |
| 31 | 31 | ... | ... |
-
Please register or login to post a comment