How to pick up weather and weather information?

I came across a problem that I would like to see if it can be solved in a way similar to that of the post office. When you have a zip code you can retrieve other data from a web service, such as the address and city of that zip code.

Regarding weather, is there some way with place information to get the temperature of the weather forecast, the time and the current temperature of that place(the intention was later to style the css of that part of the page to leave a nice look)?

Author: DiChrist, 2016-03-08

6 answers

You can get this information through Weather Service APIs, such as Yahoo!

I created and tested a usage example, as shown below:

<script>
    var callbackFunction = function(data) {
        console.log(data);
    };
</script>

<script src="https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='são paulo, sp')&format=json&callback=callbackFunction"></script>

Where:

  • format: this is the type of data that will be returned, which can be JSON or XML;
  • callback : this is the function that will handle the response of your request.

You can also add

and u = 'c'

In the WHERE clause to change for metric system and scale for Celsius.

If it is only a city, you can search WOEID first to improve response time.

For example, for São Paulo capital,

Http://woeid.rosselliot.co.nz/lookup/sao%20paulo

Would return 455827, where the final query would be:

select * from weather.forecast where woeid = 455827&format=json&callback=callbackFunction

There is this site, own Yahoo!, where you can test your yql (Yahoo Query Language).

It is worth saying that from according to the Yahoo API, the limit of daily queries is 2 thousand requests, and be aware of the terms of use, where it can only be used by individuals, non-profit companies and non-commercial use.


Remember that the Yahoo! API it's just one of the solutions, if it doesn't meet your needs, you can search for 'Weather api' or 'weather forecast api'.

 8
Author: silvalexandre, 2016-03-09 06:10:53

I found this 'API' which returns the following data:

{
 "cidade":"Sao Paulo - SP",
 "agora":{
  "data_hora":"08\/11\/2013 - 19:59",
  "descricao":"Muito Nublado (noite)",
  "temperatura":"19",
  "humidade":"73%",
  "visibilidade":"9,99 km",
  "vento_velocidade":"20,92 km\/h",
  "vento_direcao":"SE",
  "pressao":"1.015,92 mBar",
  "pressao_status":"subindo",
  "nascer_do_sol":"6:16 am",
  "por_do_sol":"7:25 pm",
  "imagem":"http:\/\/developers.agenciaideias.com.br\/images\/tempo\/27.png"
 },
 "previsoes":[
  {
   "data":"Sexta - 08\/11\/2013",
   "descricao":"Parcialmente Nublado (noite)",
   "temperatura_max":"23",
   "temperatura_min":"16",
   "imagem":"http:\/\/developers.agenciaideias.com.br\/images\/tempo\/29.png"
  },
  {
   "data":"S\u00e1bado - 09\/11\/2013",
   "descricao":"Tempo Bom (dia)",
   "temperatura_max":"27",
   "temperatura_min":"18",
   "imagem":"http:\/\/developers.agenciaideias.com.br\/images\/tempo\/34.png"
  },
  {
   "data":"Domingo - 10\/11\/2013",
   "descricao":"Ensolarado",
   "temperatura_max":"29",
   "temperatura_min":"21",
   "imagem":"http:\/\/developers.agenciaideias.com.br\/images\/tempo\/32.png"
  },
  {
   "data":"Segunda - 11\/11\/2013",
   "descricao":"Parcialmente Nublado (dia)",
   "temperatura_max":"32",
   "temperatura_min":"23",
   "imagem":"http:\/\/developers.agenciaideias.com.br\/images\/tempo\/30.png"
  },
  {
   "data":"Ter\u00e7a - 12\/11\/2013",
   "descricao":"Parcialmente Nublado (dia)",
   "temperatura_max":"30",
   "temperatura_min":"19",
   "imagem":"http:\/\/developers.agenciaideias.com.br\/images\/tempo\/30.png"
  }
 ]
}

Follow the url: http://developers.agenciaideias.com.br/tempo

I tested the request described in the documentation, with Angularjs, and returned everything right. =)

 5
Author: Rubens Barbosa, 2016-03-08 20:19:02

Climatempo (Brazilian Meteorological company) launched an API in 2017, you can nail the forecast for free..

The site is https://advisor.climatempo.com.br

There has all the documentation. Just log in with your "Facebook", "Google" or "Github", generate a token and make the request via GET.

 5
Author: Vitor Hugo Bettani, 2018-01-16 12:39:30

If it is via programming with c # I recommend using Html agility Pack, with it you can tell the source of information (Site) and inform the code in which div is the information you want being able to use for various purposes, I for example used to get the results of mega sena.

Http://html-agility-pack.net/?z=codeplex

 2
Author: Wander, 2017-09-10 16:13:00

A JSON alternative is: http://webservice.seriesanalysis.com/moment/linhares_es

Only change the name of the city followed by the state. Draw accents, example:

linhares_es,
saopaulo_sp,
vitoria_es,
riodejaneiro_rj
 1
Author: Wellington Pinto Oliveira, 2016-07-12 15:50:14

Based on silvalexandre's response
Use the link before to find out the woeid of your location

    select woeid from geo.places(1) where text='são paulo, sp'

Javascript Call the jQuery lib and

    <script>
    $.get('https://query.yahooapis.com/v1/public/yql',{
        q:'select * from weather.forecast where woeid in (455822)',
        format:'json'
    },function (res) {
        if(res){
            umi = res.query.results.channel.atmosphere.humidity;
            temp = res.query.results.channel.item.condition.temp;

            temp = Math.round((temp-32)/1.8); //F to C

            console.log(temp,umi);
        }
    },'json');
    </script>

PHP

$cont = file_get_contents("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(455822)&format=json");

$cont = json_decode($cont,1);

$umi = $cont['query']['results']['channel']['atmosphere']['humidity'];
$temp = $cont['query']['results']['channel']['item']['condition']['temp'];

$temp = intval( ($temp - 32) /1.8 ); //F to C

echo $umi." ".$temp;
 1
Author: Marlon Yow, 2017-06-20 14:54:24