장마대비 코드 수정
가장 최근 게시글이 2014년 4월 글이다. 그래 뭐라도 좀 쓰자.
심각한 결정장애자로 구성된 팀원들이 매일 점심마다 엘리베이터타고 지하 1층까지 내려와서는 서로의 눈치만 살필뿐 어디가자 말하는 사람이 없이 한동안 멍하니 서있기만 한 상황이 싫어서 만든 웹앱이 “오늘의 밥집”이다.
상암동 누리꿈스퀘어 근무자만 사용가능한 앱이다.

오늘같이 비가 퍼붓는 날은 건물 밖에 나갈 수 없으니 날씨에 따라 추천 밥집을 유동적으로 할 필요가 있겠다 싶어 현재 날씨 관련 OPEN API를 찾아서 적용하였다.
기준은 가장 쉬어 보이는 놈으로 해서 openweathermap.org 꺼로 정했다.
http://api.openweathermap.org/data/2.5/weather?q=Seoul,uk&appid=3427...
HTTP GET 메소드로 요청하면 JSON으로 반환해준다.
{ "coord": { "lon": 127, "lat": 37.52 }, "weather": [ { "id": 301, "main": "Drizzle", "description": "drizzle", "icon": "09n" }, { "id": 701, "main": "Mist", "description": "mist", "icon": "50n" } ], "base": "stations", "main": { "temp": 292.66, "pressure": 1012, "humidity": 88, "temp_min": 290.15, "temp_max": 296.15 }, "visibility": 10000, "wind": { "speed": 1.5, "deg": 320 }, "clouds": { "all": 90 }, "dt": 1467724800, "sys": { "type": 1, "id": 8519, "message": 0.0104, "country": "KR", "sunrise": 1467663409, "sunset": 1467716182 }, "id": 1846735, "name": "Chamsil", "cod": 200 }
여기서 weather[0] –> main 에 해당하는 문자열만 끄집어 내서 Rain, Storm … 이면 건물 밖 밥집은 제외토록 하였다.
function currWeather(){ var xhr = new XMLHttpRequest(); var curr = "Clear"; xhr.onreadystatechange=function() { if(xhr.status == 200 && xhr.readyState==4) curr = JSON.parse(xhr.responseText).weather[0].main; } xhr.open('GET', 'http://api.openweathermap.org/data/2.5/weather?" + "q=Seoul&appid=3427...',false); xhr.send(); return curr; }
태그: javascript, programming