Totally new to python and just messing around with a Blinkt! to see what it can do. Apologies for any inadvertent forum faux pas. I have been mucking around with the openweathermap API and the example blinkt_thermo.py and have thus far made a thermometer which changes colour based on temperature, and then cycles to show different data, for example a humidity gauge.
I would like to colour code the ‘description’ (weather condition) so that, for example, if weather.description is “overcast clouds” the blinkt lights up all white, light blue for a clear day, etc.
As I said I’ve fudged together a few bits of code from different places so what I have is not at all elegant. At the moment, I can get it to display the white colour bar for the overcast day with:
Code: Select all
def draw_desc(desc): if desc == 'overcast clouds': blinkt.set_all(255, 255, 255, 0.1) blinkt.show()
Where desc is a previously defined global variable added in to the original blinkt_thermo.py update_weather function as desc = weather_data['weather']['description']
I suspect a better way to achieve what I am after would be to use the weather.id rather than .description, (https://openweathermap.org/weather-conditions) so that for example anything with the id in the range 200-232 (thunderstorm) would show purple, or whatever.
I can’t figure out a way to do this with my limited knowledge beyond using a whopping great bunch of if-elif statements like:
Code: Select all
def draw_id(id): if id in range(200, 232): #thunderstorms blinkt.set_all(128, 0, 128, 0.1) blinkt.show() elif id in range(300, 321): #drizzle blinkt.set_all(0, 0, 255, 0.1) blinkt.show() elif
And so on.
As per the website there are seven groups of weather conditions that would need “colour coding”.
Any suggestions, other than “why bother?”?