api link to get current day forecast

  • 1
  • Question
  • Updated 6 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

milneepp

  • 1 Post
  • 0 Reply Likes

Posted 6 years ago

  • 1
Photo of Brendan Hayes

Brendan Hayes, Official Rep

  • 962 Posts
  • 122 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:
 

<simpleforecast>
<forecastdays>
<forecastday>
<date>
<epoch>1348110000</epoch>
<pretty_short>9:00 PM MDT</pretty_short>
<pretty>9:00 PM MDT on September 19, 2012</pretty>
<day>19</day>
<month>9</month>
<year>2012</year>
<yday>262</yday>
<hour>21</hour>
<min>00</min>
<sec>0</sec>
<isdst>1</isdst>
<monthname>September</monthname>
<weekday_short>Wed</weekday_short>
<weekday>Wednesday</weekday>
<ampm>PM</ampm>
<tz_short>MDT</tz_short>
<tz_long>America/Edmonton</tz_long>
</date>
<period>1</period>
<high>
<fahrenheit>72</fahrenheit>
<celsius>22</celsius>
</high>
<low>
<fahrenheit>37</fahrenheit>
<celsius>3</celsius>
</low>
<conditions>Mostly Cloudy</conditions>

<icon>mostlycloudy</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/mostlycloudy.gif</icon_url>
<skyicon>cloudy</skyicon>
<pop>0</pop>
<qpf_allday>
<in>0.00</in>
<mm>0.0</mm>
</qpf_allday>
<qpf_day>
<in>0.00</in>
<mm>0.0</mm>
</qpf_day>
<qpf_night>
<in>0.00</in>
<mm>0.0</mm>
</qpf_night>
<snow_allday>
<in>0</in>
<cm>0</cm>
</snow_allday>
<snow_day>
<in>0</in>
<cm>0</cm>
</snow_day>
<snow_night>
<in>0</in>
<cm>0</cm>
</snow_night>
<maxwind>
<mph>9</mph>
<kph>14</kph>
<dir>WNW</dir>
<degrees>298</degrees>
</maxwind>
<avewind>
<mph>7</mph>
<kph>11</kph>
<dir>WNW</dir>
<degrees>294</degrees>
</avewind>
<avehumidity>39</avehumidity>
<maxhumidity>100</maxhumidity>
<minhumidity>26</minhumidity>
</forecastday>
Photo of En0c

En0c

  • 6 Posts
  • 0 Reply Likes
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);
setDoLow(Double.parseDouble(result));

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.