/** * Gets data from Yahoo RSS weather feed, picks off some information, * and prints it to the console. * * Copyright (C) 2012-2013 Mithat Konar */ // Constants: // change the URL to get the desired location and units // (see http://developer.yahoo.com/weather/). final String URL = "http://weather.yahooapis.com/forecastrss?w=12781882&u=f"; // path in XML data to current conditions: final String ELEMENT_CONDITION="channel/item/yweather:condition"; // attribute name in element above for current temperature: final String ATTRIBUTE_CONDITION_TEMPERATURE = "temp"; // path in XML data to element that holds units of measurement: final String ELEMENT_UNITS = "channel/yweather:units"; // attribute name in element above that holds units for temperature: final String ATTRIBUTE_UNIT_TEMPERATURE = "temperature"; // misc. final int CANVAS_BORDER=10; // Functions: void setup() { size(160, 90); smooth(); try { XML weather = loadXML(URL); // instantiate an XML object from URL. XML condition = weather.getChild(ELEMENT_CONDITION); // pull current cond. XML units = weather.getChild(ELEMENT_UNITS); // pull units data // Turn the canvas green to show that all went well. background(#00cc00); // "\u00b0" is the degree symbol println("The content:"); println(condition.getInt(ATTRIBUTE_CONDITION_TEMPERATURE) + "\u00b0 " + units.getString(ATTRIBUTE_UNIT_TEMPERATURE)); println("End content."); } catch (Exception e) { println("Problem loading " + URL); println(e); // Turn the canvas red with a big 'X' in it to indicate error. background(#ff0000); strokeWeight(5); line(CANVAS_BORDER, CANVAS_BORDER, width-CANVAS_BORDER, height-CANVAS_BORDER); line(CANVAS_BORDER, height-CANVAS_BORDER, width-CANVAS_BORDER, CANVAS_BORDER); } println("Exiting app."); }