Skip to content

Instantly share code, notes, and snippets.

@ericoporto
Created July 28, 2015 00:39
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ericoporto/c867f7d67c7ced22c7e1 to your computer and use it in GitHub Desktop.
Save ericoporto/c867f7d67c7ced22c7e1 to your computer and use it in GitHub Desktop.
Yahoo Weather API Condition Codes in Brazilian Portuguese (Códigos do Yahoo Weather em Português - Brasil)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2015 Erico Vieira Porto
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# This is a loose translation of the Yahoo Weather API Condition Codes from en-us
# to pt-br (Brazilian Portuguese). I needed this for a twitter bot.
# Source of the original Condition Codes is here:
# https://developer.yahoo.com/weather/documentation.html#codes
# If you have better translations, please send me: https://github.com/ericoporto/
ywcc_ptbr = {
'0': 'tornado', # tornado
'1': 'tempestade tropical', # tropical storm
'2': 'furacão', # hurricane
'3': 'tempestade severa', # severe thunderstorms
'4': 'trovoadas', # thunderstorms
'5': 'chuva e neve', # mixed rain and snow
'6': 'chuva e granizo fino', # mixed rain and sleet
'7': 'neve e granizo fino', # mixed snow and sleet
'8': 'garoa gélida', # freezing drizzle
'9': 'garoa', # drizzle
'10': 'chuva gélida', # freezing rain
'11': 'chuvisco', # showers
'12': 'chuva', # showers
'13': 'neve em flocos finos', # snow flurries
'14': 'leve precipitação de neve', # light snow showers
'15': 'ventos com neve', # blowing snow
'16': 'neve', # snow
'17': 'chuva de granizo', # hail
'18': 'pouco granizo', # sleet
'19': 'pó em suspensão', # dust
'20': 'neblina', # foggy
'21': 'névoa seca', # haze
'22': 'enfumaçado', # smoky
'23': 'vendaval', # blustery
'24': 'ventando', # windy
'25': 'frio', # cold
'26': 'nublado', # cloudy
'27': 'muitas nuvens (noite)', # mostly cloudy (night)
'28': 'muitas nuvens (dia)', # mostly cloudy (day)
'29': 'parcialmente nublado (noite)', # partly cloudy (night)
'30': 'parcialmente nublado (dia)', # partly cloudy (day)
'31': 'céu limpo (noite)', # clear (night)
'32': 'ensolarado', # sunny
'33': 'tempo bom (noite)', # fair (night)
'34': 'tempo bom (dia)', # fair (day)
'35': 'chuva e granizo', # mixed rain and hail
'36': 'quente', # hot
'37': 'tempestades isoladas', # isolated thunderstorms
'38': 'tempestades esparsas', # scattered thunderstorms
'39': 'tempestades esparsas', # scattered thunderstorms
'40': 'chuvas esparsas', # scattered showers
'41': 'nevasca', # heavy snow
'42': 'tempestades de neve esparsas', # scattered snow showers
'43': 'nevasca', # heavy snow
'44': 'parcialmente nublado', # partly cloudy
'45': 'chuva com trovoadas', # thundershowers
'46': 'tempestade de neve', # snow showers
'47': 'relâmpagos e chuvas isoladas', # isolated thundershowers
'3200': 'não disponível' # not available
}
@ojvribeiro
Copy link

Obrigado. Isso foi de grande ajuda pro meu projeto, onde usei JavaScript e a biblioteca SimpleWeather.js. Vou deixar abaixo para quem quiser fazer uso.

// SimpleWeather.js
// Link: http://simpleweatherjs.com

$(document).ready(function () {
  $.simpleWeather({
    location: 'NOME_DA_CIDADE',
    woeid: '',
    unit: 'c',
    success: function(weather) {

var currently = weather.currently;
html = '<i class="icon-'+weather.code+'"></i> '
+weather.temp+'°'+weather.units.temp
+'<div class="w-location">'+weather.city+', '+weather.region+'</div><div id="w-currently" class="w-location">'+currently+'</div>';
$("#weather").html(html);

      var currently = weather.currently;
      switch(currently) {
    case 'Tornado':
      document.getElementById('w-currently').innerHTML = 'Tornado';                       // tornado
        break;
    case 'Tropical Storm':
      document.getElementById('w-currently').innerHTML = 'Tempestade tropical';           // tropical storm
        break;
    case 'Hurricane':
      document.getElementById('w-currently').innerHTML = 'Furacão';                       // hurricane
        break;
    case 'Severe Thunderstorms':
      document.getElementById('w-currently').innerHTML = 'Tempestade severa';             // severe thunderstorms
        break;
    case 'Thunderstorms':
      document.getElementById('w-currently').innerHTML = 'Trovoadas';                     // thunderstorms
        break;
    case 'Mixed Rain And Snow':
      document.getElementById('w-currently').innerHTML = 'Chuva e neve';                  // mixed rain and snow
        break;
    case 'Mixed Rain And Sleet':
      document.getElementById('w-currently').innerHTML = 'Chuva e granizo fino';          // mixed rain and sleet
        break;
    case 'Mixed Snow And Sleet':
      document.getElementById('w-currently').innerHTML = 'Neve e granizo fino';           // mixed snow and sleet
        break;
    case 'Freezing Drizzle':
      document.getElementById('w-currently').innerHTML = 'Garoa gélida';                  // freezing drizzle
        break;
    case 'Drizzle':
      document.getElementById('w-currently').innerHTML = 'Garoa';                         // drizzle
        break;
    case 'Freezing Rain':
      document.getElementById('w-currently').innerHTML = 'Chuva gélida';                  // freezing rain
        break;
    case 'Showers':
      document.getElementById('w-currently').innerHTML = 'Chuvisco';                      // showers
        break;
    case 'Showers':
      document.getElementById('w-currently').innerHTML = 'Chuva';                         // showers
        break;
    case 'Snow Flurries':
      document.getElementById('w-currently').innerHTML = 'Neve em flocos finos';          // snow flurries
        break;
    case 'Light Snow Showers':
      document.getElementById('w-currently').innerHTML = 'Leve precipitação de neve';     // light snow showers
        break;
    case 'Blowing Snow':
      document.getElementById('w-currently').innerHTML = 'Ventos com neve';               // blowing snow
        break;
    case 'Snow':
      document.getElementById('w-currently').innerHTML = 'Neve';                          // snow
        break;
    case 'Hail':
      document.getElementById('w-currently').innerHTML = 'Chuva de granizo';              // hail
        break;
    case 'Sleet':
      document.getElementById('w-currently').innerHTML = 'Pouco granizo';                 // sleet
        break;
    case 'Dust':
      document.getElementById('w-currently').innerHTML = 'Pó em suspensão';               // dust
        break;
    case 'Foggy':
      document.getElementById('w-currently').innerHTML = 'Neblina';                       // foggy
        break;
    case 'Haze':
      document.getElementById('w-currently').innerHTML = 'Névoa seca';                    // haze
        break;
    case 'Smoky':
      document.getElementById('w-currently').innerHTML = 'Enfumaçado';                    // smoky
        break;
    case 'Blustery':
      document.getElementById('w-currently').innerHTML = 'Vendaval';                      // blustery
        break;
    case 'Windy':
      document.getElementById('w-currently').innerHTML = 'Ventando';                      // windy
        break;
    case 'Cold':
      document.getElementById('w-currently').innerHTML = 'Frio';                          // cold
        break;
    case 'Cloudy':
      document.getElementById('w-currently').innerHTML = 'Nublado';                       // cloudy
        break;
    case 'Mostly Cloudy':
      document.getElementById('w-currently').innerHTML = 'Muitas nuvens';         // mostly cloudy (night)
        break;
    case 'Mostly Cloudy':
      document.getElementById('w-currently').innerHTML = 'Muitas nuvens';           // mostly cloudy (day)
        break;
    case 'Partly Cloudy':
      document.getElementById('w-currently').innerHTML = 'Parcialmente nublado';  // partly cloudy (night)
        break;
    case 'Partly Cloudy':
      document.getElementById('w-currently').innerHTML = 'Parcialmente nublado';    // partly cloudy (day)
        break;
    case 'Clear':
      document.getElementById('w-currently').innerHTML = 'Céu limpo';             // clear (night)
        break;
    case 'Sunny':
      document.getElementById('w-currently').innerHTML = 'Ensolarado';                    // sunny
        break;
    case 'Fair':
      document.getElementById('w-currently').innerHTML = 'Tempo bom';             // fair (night)
        break;
    case 'Fair':
      document.getElementById('w-currently').innerHTML = 'Tempo bom';               // fair (day)
        break;
    case 'Mixed Rain And Rail':
      document.getElementById('w-currently').innerHTML = 'Chuva e granizo';               // mixed rain and hail
        break;
    case 'Hot':
      document.getElementById('w-currently').innerHTML = 'Quente';                        // hot
        break;
    case 'Isolated Thunderstorms':
      document.getElementById('w-currently').innerHTML = 'Tempestades isoladas';          // isolated thunderstorms
        break;
    case 'Scattered Thunderstorms':
      document.getElementById('w-currently').innerHTML = 'Tempestades esparsas';          // scattered thunderstorms
        break;
    case 'Scattered Thunderstorms':
      document.getElementById('w-currently').innerHTML = 'Tempestades esparsas';          // scattered thunderstorms
        break;
    case 'Scattered Showers':
      document.getElementById('w-currently').innerHTML = 'Chuvas esparsas';               // scattered showers
        break;
    case 'Heavy Snow':
      document.getElementById('w-currently').innerHTML = 'Nevasca';                       // heavy snow
        break;
    case 'Scattered Snow Showers':
      document.getElementById('w-currently').innerHTML = 'Tempestades de neve esparsas';  // scattered snow showers
        break;
    case 'Heavy Snow':
      document.getElementById('w-currently').innerHTML = 'Nevasca';                       // heavy snow
        break;
    case 'Partly Cloudy':
      document.getElementById('w-currently').innerHTML = 'Parcialmente nublado';          // partly cloudy
        break;
    case 'Thundershowers':
      document.getElementById('w-currently').innerHTML = 'Chuva com trovoadas';           // thundershowers
        break;
    case 'Snow Showers':
      document.getElementById('w-currently').innerHTML = 'Tempestade de neve';            // snow showers
        break;
    case 'Isolated Thundershowers':
      document.getElementById('w-currently').innerHTML = 'relâmpagos e chuvas isoladas';  // isolated thundershowers
        break;
    case 'Not Available': document.getElementById('w-currently').innerHTML = 'Não disponível'               // not available
    };


    }, error: function(error) {$("#weather").html('<p>'+error+'</p>');}
  });
});

@ericoporto
Copy link
Author

@jvribeiro você é meu primeiro comentário no Gist e fico feliz de ter sido útil! :D Eu usei essa lista aí aqui: https://github.com/ericoporto/Chove-Agora

@garbinmarcelo
Copy link

Isso vai me ajudar! Obrigado =)

@th4deu
Copy link

th4deu commented Jul 13, 2016

Esta lista de códigos não tem preço! Mandou bem!!! Obrigado!

@GitClickOk
Copy link

Olá, Érico, obrigado pela lista. Converti numa array em javascript se ajudar alguém. No fim ainda deixo a função que recebe um código e retorna a tradução.

        var ywcc_ptbr = [
            [ '0', 'tornado' ],
            [ '1', 'tempestade tropical' ],
            [ '2', 'furacão' ],
            [ '3', 'tempestade severa' ],
            [ '4', 'trovoadas' ],
            [ '5', 'chuva e neve' ],
            [ '6', 'chuva e granizo fino' ],
            [ '7', 'neve e granizo fino' ],
            [ '8', 'garoa gélida' ],
            [ '9', 'garoa' ],
            [ '10', 'chuva gélida' ],
            [ '11', 'chuvisco' ],
            [ '12', 'chuva' ],
            [ '13', 'neve em flocos finos' ],
            [ '14', 'leve precipitação de neve' ],
            [ '15', 'ventos com neve' ],
            [ '16', 'neve' ],
            [ '17', 'chuva de granizo' ],
            [ '18', 'pouco granizo' ],
            [ '19', 'pó em suspensão' ],
            [ '20', 'neblina' ],
            [ '21', 'névoa seca' ],
            [ '22', 'enfumaçado' ],
            [ '23', 'vendaval' ],
            [ '24', 'ventando' ],
            [ '25', 'frio' ],
            [ '26', 'nublado' ],
            [ '27', 'muitas nuvens (noite)' ],
            [ '28', 'muitas nuvens (dia)' ],
            [ '29', 'parcialmente nublado (noite)' ],
            [ '30', 'parcialmente nublado (dia)' ],
            [ '31', 'céu limpo (noite)' ],
            [ '32', 'ensolarado' ],
            [ '33', 'tempo bom (noite)' ],
            [ '34', 'tempo bom (dia)' ],
            [ '35', 'chuva e granizo' ],
            [ '36', 'quente' ],
            [ '37', 'tempestades isoladas' ],
            [ '38', 'tempestades esparsas' ],
            [ '39', 'tempestades esparsas' ],
            [ '40', 'chuvas esparsas' ],
            [ '41', 'nevasca' ],
            [ '42', 'tempestades de neve esparsas' ],
            [ '43', 'nevasca' ],
            [ '44', 'parcialmente nublado' ],
            [ '45', 'chuva com trovoadas' ],
            [ '46', 'tempestade de neve' ],
            [ '47', 'relâmpagos e chuvas isoladas' ],
            [ '3200', 'não disponível' ]
        ];	

        function translateCode(code) {
            var arrayLength = ywcc_ptbr.length;
            for (var i = 0; i < arrayLength; i++) {
                if (code == ywcc_ptbr[i][0]) {
                    return ywcc_ptbr[i][1];
                }                
            }
        };

@felipethomas82
Copy link

Olá Érico, me salvou um bom tempo com este código. Refiz convertendo para um objeto Javascript.

var ywcc_ptbr = {
    '0':  'tornado',                       // tornado
    '1':  'tempestade tropical',           // tropical storm
    '2':  'furacão',                       // hurricane
    '3':  'tempestade severa',             // severe thunderstorms
    '4':  'trovoadas',                     // thunderstorms
    '5':  'chuva e neve',                  // mixed rain and snow
    '6':  'chuva e granizo fino',          // mixed rain and sleet
    '7':  'neve e granizo fino',           // mixed snow and sleet
    '8':  'garoa gélida',                  // freezing drizzle
    '9':  'garoa',                         // drizzle
    '10': 'chuva gélida',                  // freezing rain
    '11': 'chuvisco',                      // showers
    '12': 'chuva',                         // showers
    '13': 'neve em flocos finos',          // snow flurries
    '14': 'leve precipitação de neve',     // light snow showers
    '15': 'ventos com neve',               // blowing snow
    '16': 'neve',                          // snow
    '17': 'chuva de granizo',              // hail
    '18': 'pouco granizo',                 // sleet
    '19': 'pó em suspensão',               // dust
    '20': 'neblina',                       // foggy
    '21': 'névoa seca',                    // haze
    '22': 'enfumaçado',                    // smoky
    '23': 'vendaval',                      // blustery
    '24': 'ventando',                      // windy
    '25': 'frio',                          // cold
    '26': 'nublado',                       // cloudy
    '27': 'muitas nuvens (noite)',         // mostly cloudy (night)
    '28': 'muitas nuvens (dia)',           // mostly cloudy (day)
    '29': 'parcialmente nublado (noite)',  // partly cloudy (night)
    '30': 'parcialmente nublado (dia)',    // partly cloudy (day)
    '31': 'céu limpo (noite)',             // clear (night)
    '32': 'ensolarado',                    // sunny
    '33': 'tempo bom (noite)',             // fair (night)
    '34': 'tempo bom (dia)',               // fair (day)
    '35': 'chuva e granizo',               // mixed rain and hail
    '36': 'quente',                        // hot
    '37': 'tempestades isoladas',          // isolated thunderstorms
    '38': 'tempestades esparsas',          // scattered thunderstorms
    '39': 'tempestades esparsas',          // scattered thunderstorms
    '40': 'chuvas esparsas',               // scattered showers
    '41': 'nevasca',                       // heavy snow
    '42': 'tempestades de neve esparsas',  // scattered snow showers
    '43': 'nevasca',                       // heavy snow
    '44': 'parcialmente nublado',          // partly cloudy
    '45': 'chuva com trovoadas',           // thundershowers
    '46': 'tempestade de neve',            // snow showers
    '47': 'relâmpagos e chuvas isoladas',  // isolated thundershowers
    '3200': 'não disponível'               // not available
  }

Daí para usar, basta acessar a propriedade diretamente com o código.

var code = channel.item.condition.code;
console.log(ywcc_ptbr[code]);

@samuelcarreira
Copy link

@felipethomas82 obrigado pela partilha desse código!

@RenanSMoura
Copy link

RenanSMoura commented Sep 25, 2017

Galera, também fiz essa lista para usar em um App Android.

Só criar um arquivo chamado array.xml na pasta res/values/

Para acessar isso dentro do código java só usar

suaActivity.getResources().getStringArray(R.array.climate_conditions_pt_br)[code];

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="climate_conditions_pt_br">
        <item>Tornado</item>
        <item>Tempestade tropical</item>
        <item>Furacão</item>
        <item>Tempestade Severa</item>
        <item>Trovoadas</item>
        <item>Chuva e neve</item>
        <item>Chuva e granizo fino</item>
        <item>Neve e granizo fino</item>
        <item>Garoa gélida</item>
        <item>Garoa</item>
        <item>Chuva gélida</item>
        <item>Chuvisco</item>
        <item>Chuva</item>
        <item>Neve em flocos finos</item>
        <item>Leve precipitação de neve</item>
        <item>Ventos com neve</item>
        <item>Neve</item>
        <item>Chuva de granizo</item>
        <item>Pouco granizo</item>
        <item>Pó em suspensão</item>
        <item>Neblina</item>
        <item>Névoa seca</item>
        <item>Enfumaçado</item>
        <item>Vendaval</item>
        <item>Ventando</item>
        <item>Frio</item>
        <item>Nublado</item>
        <item>Muitas nuvens (Noite)</item>
        <item>Muitas nuvens (Dia)</item>
        <item>Parcialmente nublado (Noite)</item>
        <item>Parcialmente nublado (Dia)</item>
        <item>Céu limpo (Noite)</item>
        <item>Ensolarado</item>
        <item>Tempo bom (Noite)</item>
        <item>Tempo bom (Dia)</item>
        <item>Chuva e granizo</item>
        <item>Quente</item>
        <item>Tempestades isoladas</item>
        <item>Tempestades esparsas</item>
        <item>Tempestades esparsas</item>
        <item>Chuvas esparsas</item>
        <item>Nevasca</item>
        <item>Tempestades de neve esparsas</item>
        <item>Nevasca</item>
        <item>Parcialmente nublado</item>
        <item>Chuva com trovoadas</item>
        <item>Tempestade de neve</item>
        <item>Relâmpagos e chuvas isoladas</item>
        <item>Não disponível</item>
    </string-array>
</resources> 

@luizvicenteps
Copy link

@felipethomas82 obrigado pela partilha desse código! /2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment