-
-
Save ericoporto/c867f7d67c7ced22c7e1 to your computer and use it in GitHub Desktop.
#!/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 | |
} |
@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
Isso vai me ajudar! Obrigado =)
Esta lista de códigos não tem preço! Mandou bem!!! Obrigado!
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];
}
}
};
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]);
@felipethomas82 obrigado pela partilha desse código!
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>
@felipethomas82 obrigado pela partilha desse código! /2
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.