| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 
 |  
var querystring = require('querystring');
var request     = require("request");
var result = '';
var text = '';
 
var openWeatherMapQuery = querystring.stringify({
  q: "Bourges, France",
  lang: "fr",
  units: "metric"
});
var openWeatherMapURL = "http://api.openweathermap.org/data/2.5/weather?"+ openWeatherMapQuery;
 
request({
  url: openWeatherMapURL,
  json: true // Nous recevrons un JSON
}, function (error, response, resp) {
 
  if (!error && response.statusCode === 200) {
 
    var text = "Bulletin météo : "
    text += resp.weather[0].description
    text += ". Il fait actuellement "+ Math.round(resp.main.temp) +" degrés."
 
    var result = querystring.stringify({
      tl: "fr",
      q:  text,
      ie: "UTF-8"
    });
 
    console.log("Météo construite :");
    console.log(text);
    console.log(resp.main.temp);
 
  } else {
 
    console.log("Une erreur est survenue.");
  }
})
 
module.exports.result = result;
module.exports.text = text; | 
Partager