Minor improvements + bugfix

OWM uses UTC-time to provide weather forecasts. Previously, a timezone-aware stamp was used which caused problems with the forecasts for some users. By switching to UTC time, the problem is fixed.
In case somethign goes wrong, the error message will be printed directly on the coresponding section.
Added support for 2-colour mode (due to new driver files).
This commit is contained in:
Ace 2020-02-04 16:49:20 +01:00 committed by GitHub
parent 407dbcffde
commit 30a202fe50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -171,7 +171,7 @@ def generate_image():
forecast = owm.three_hours_forecast(location) forecast = owm.three_hours_forecast(location)
"""Round the hour to the nearest multiple of 3""" """Round the hour to the nearest multiple of 3"""
now = arrow.now(tz=get_tz()) now = arrow.utcnow()
if (now.hour % 3) != 0: if (now.hour % 3) != 0:
hour_gap = 3 - (now.hour % 3) hour_gap = 3 - (now.hour % 3)
else: else:
@ -258,9 +258,10 @@ def generate_image():
write_text(icon_small, icon_small, '\uf0b1', windspeed_icon_now_pos, write_text(icon_small, icon_small, '\uf0b1', windspeed_icon_now_pos,
font = w_font, fill_height = 0.9, rotation = -wind_degrees) font = w_font, fill_height = 0.9, rotation = -wind_degrees)
write_text(coloumn_width-icon_small, row_height, write_text(coloumn_width-icon_small, row_height, temperature_now,
temperature_now, temperature_now_pos, font = font, colour = temperature_now_pos, font = font, colour= red_temp(temperature_now))
red_temp(temperature_now))
write_text(coloumn_width-icon_small, row_height, humidity_now+'%', write_text(coloumn_width-icon_small, row_height, humidity_now+'%',
humidity_now_pos, font = font) humidity_now_pos, font = font)
write_text(coloumn_width-icon_small, row_height, wind, write_text(coloumn_width-icon_small, row_height, wind,
@ -326,24 +327,31 @@ def generate_image():
draw.line((coloumn5, line_start_y, coloumn5, line_end_y), fill='black') draw.line((coloumn5, line_start_y, coloumn5, line_end_y), fill='black')
draw.line((coloumn6, line_start_y, coloumn6, line_end_y), fill='black') draw.line((coloumn6, line_start_y, coloumn6, line_end_y), fill='black')
draw.line((coloumn7, line_start_y, coloumn7, line_end_y), fill='black') draw.line((coloumn7, line_start_y, coloumn7, line_end_y), fill='black')
if three_colour_support == True:
draw_col.line((0, top_section_height-border_top, top_section_width-
border_left, top_section_height-border_top), fill='black', width=3)
else:
draw.line((0, top_section_height-border_top, top_section_width- draw.line((0, top_section_height-border_top, top_section_width-
border_left, top_section_height-border_top), border_left, top_section_height-border_top), fill='black', width=3)
fill='red' if three_colour_support == 'True' else 'black' , width=3)
weather_image = crop_image(image, 'top_section') weather_image = crop_image(image, 'top_section')
weather_image.save(image_path+'inkycal_weather.png') weather_image.save(image_path+'inkycal_weather.png')
if three_colour_support == True:
weather_image_col = crop_image(image_col, 'top_section')
weather_image_col.save(image_path+'inkycal_weather_col.png')
print('Done') print('Done')
except Exception as e: except Exception as e:
"""If no response was received from the openweathermap """If something went wrong, print a Error message on the Terminal"""
api server, add the cloud with question mark""" print('Failed!')
print('__________OWM-ERROR!__________') print('Error in weather module!')
print('Reason: ',e) print('Reason: ',e)
write_text(icon_medium, icon_medium, '\uf07b', weather_icon_now_pos, clear_image('top_section')
font = w_font, fill_height = 1.0) write_text(top_section_width, top_section_height, str(e),
message = 'No internet connectivity or API timeout' (0, 0), font = font)
write_text(coloumn_width*6, row_height, message, humidity_icon_now_pos,
font = font)
weather_image = crop_image(image, 'top_section') weather_image = crop_image(image, 'top_section')
weather_image.save(image_path+'inkycal_weather.png') weather_image.save(image_path+'inkycal_weather.png')
pass pass