Wiki

Reso-nance numérique | Arts et cultures libres

Outils du site


Panneau latéral

logiciels:processing:data:accueil

Table des matières

Data

Météo

Récupérer les données météo des villes via des requêtes envoyées à Yahoo. Processing analyse et récupère les données envoyées au format XML.

Le code WOEID correspond à la ville, on peut le récupérer ici : http://woeid.rosselliot.co.nz/

/* 
 * Test Weather (Yahoo URL)
 * User weather data of cities from Yahoo website
 * See requests documentation at https://developer.yahoo.com/weather/
 * Find city code here : http://woeid.rosselliot.co.nz/
 */
 
// Url requests data (WOEID number is the City Code)
String url1 = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid=4177";
String url2 = "https://query.yahooapis.com/v1/public/yql?q=select%20wind%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22chicago%2C%20il%22)&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
 
XML xml;
 
 
void setup() {
  // Get data from XMl parsing
  int temperature = getTemperature(url1);
  int wind = getWind(url2);
  // Display data
  text("T°: "+ temperature, 10, 20);
  text("Wind: "+ wind, 10, 50);
}
 
void draw(){
}
 
 
int getWind(String _url) 
{
  xml = loadXML(_url);
  XML yweather = xml.getChild("results/channel/yweather:wind");
  println("Weather (Wind) : " + yweather);
  return yweather.getInt("speed");
}
 
int getTemperature( String _url)
{
  xml = loadXML(_url);
  XML yweather = xml.getChild("results/channel/item/yweather:condition"); 
  println("Weather (Temperature) : " + yweather);
 // println("Text : "+ yweather.getString("text"));
 // println("Temperature : "+ yweather.getInt("temp"));
 // println("Date : "+ yweather.getString("date"));
 return yweather.getInt("temp");
}
/home/resonancg/www/wiki/data/pages/logiciels/processing/data/accueil.txt · Dernière modification: 2017/03/08 11:54 de resonance