api link to get current day forecast

  • 1
  • Question
  • Updated 8 years ago
I am trying to get the forecast for the current day (as in forecasted high and low), but am having troubles putting the link together (ie http://api.wunderground.com/api//fore...
Photo of milneepp


  • 1 Post
  • 0 Reply Likes

Posted 8 years ago

  • 1
Photo of Brendan Hayes

Brendan Hayes, Official Rep

  • 962 Posts
  • 124 Reply Likes
In the URL you mentioned, when your key is listed in the URL, use the simpleforecast for today's high/low. It will always start with today's forecast. This is what the XML looks like:

<pretty_short>9:00 PM MDT</pretty_short>
<pretty>9:00 PM MDT on September 19, 2012</pretty>
<conditions>Mostly Cloudy</conditions>

Photo of En0c


  • 6 Posts
  • 1 Reply Like
If you're trying to get current day you can do it pretty easily with java, I do it now like this.

DefaultHttpClient httpclient = new DefaultHttpClient();

HttpGet get = new HttpGet("http://api.wunderground.com/api/YOUR-..." + getZIP() + ".xml""); // Pulls zip code from child object via method

HttpResponse response = httpclient.execute(get);
//System.out.println("Http Status Code: " + response.getStatusLine().getStatusCode()); //HTTP status returned off request
InputStream in = response.getEntity().getContent();

// Create an XML reader
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse(in);

//Parse the Xml.
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile("//response/forecast/simpleforecast/forecastdays/forecastday[1]/high/fahrenheit/text()");

result = (String) expr.evaluate(doc, XPathConstants.STRING);

Where getZip() returns the 5 digit zip code you want to return conditions on. setDoHigh is a variable setter since DoHigh is private. Otherwise that's complete except for imports.