String zipcode = request.getParameter("k");
if (zipcode == null || "".equals(zipcode)) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing zipcode (k=?)");
return;
}
Forecast forecast = ofy().load().type(Forecast.class).id(zipcode).now();
if (forecast == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND,
"I don't have information for that zip code");
return;
}
String param = request.getParameter("v");
if (null == param || "".equals(param)) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Use a param: {high,low,pop,all}");
return;
}
if ("forecasthigh".equals(param)) {
out.println(forecast.getForecastHigh());
}
if ("forecastlow".equals(param)) {
out.println(forecast.getForecastLow());
}
if ("forecastpop".equals(param)) {
out.println(forecast.getForecastPop());
}
if ("forecastall".equals(param)) {
out.println("high=" + forecast.getForecastHigh());
out.println("low=" + forecast.getForecastLow());
out.println("pop=" + forecast.getForecastPop());
out.println("last update=" + forecast.getLastUpdate().getTime() / 1000);
out.println("last update(human)=" + forecast.getLastUpdate());
}
}
}