Implemented abstract weather forecast to main file and ignored debug image.
This commit is contained in:
parent
4c127179a9
commit
1b9ed82b40
2 changed files with 64 additions and 68 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@
|
||||||
/Calendar/__pycache__/settings.cpython-36.pyc
|
/Calendar/__pycache__/settings.cpython-36.pyc
|
||||||
/Calendar/__pycache__
|
/Calendar/__pycache__
|
||||||
/Calendar/design_exported.png
|
/Calendar/design_exported.png
|
||||||
|
/design_exported.png
|
||||||
|
|
|
@ -17,6 +17,7 @@ from icon_positions_locations import *
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont, ImageOps
|
from PIL import Image, ImageDraw, ImageFont, ImageOps
|
||||||
import pyowm
|
import pyowm
|
||||||
|
import OwmForecasts
|
||||||
from ics import Calendar
|
from ics import Calendar
|
||||||
try:
|
try:
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
@ -121,55 +122,48 @@ def main():
|
||||||
|
|
||||||
""" Handling Openweathermap API"""
|
""" Handling Openweathermap API"""
|
||||||
print("Connecting to Openweathermap API servers...")
|
print("Connecting to Openweathermap API servers...")
|
||||||
owm = pyowm.OWM(api_key)
|
owm = OwmForecasts.OwmForecasts(api_key, units=units)
|
||||||
if owm.is_API_online() is True:
|
if owm.is_available() is True:
|
||||||
observation = owm.weather_at_place(location)
|
forecast = owm.get_today_forecast(location)
|
||||||
|
|
||||||
print("weather data:")
|
print("weather data:")
|
||||||
weather = observation.get_weather()
|
|
||||||
weathericon = weather.get_weather_icon_name()
|
|
||||||
Humidity = str(weather.get_humidity())
|
|
||||||
cloudstatus = str(weather.get_clouds())
|
|
||||||
weather_description = (str(weather.get_status()))
|
|
||||||
|
|
||||||
if units == "metric":
|
if forecast.units == "metric":
|
||||||
Temperature = str(int(weather.get_temperature(unit='celsius')['temp']))
|
write_text(50, 35, forecast.air_temperature + " °C", (334, 0))
|
||||||
windspeed = str(int(weather.get_wind()['speed']))
|
write_text(100, 35, forecast.wind_speed + " km/h", (114, 0))
|
||||||
write_text(50, 35, Temperature + " °C", (334, 0))
|
|
||||||
write_text(100, 35, windspeed+" km/h", (114, 0))
|
|
||||||
|
|
||||||
if units == "imperial":
|
if forecast.units == "imperial":
|
||||||
Temperature = str(int(weather.get_temperature('fahrenheit')['temp']))
|
write_text(50, 35, forecast.air_temperature + " °F", (334, 0))
|
||||||
windspeed = str(int(weather.get_wind()['speed']*0.621))
|
write_text(100, 35, forecast.wind_speed + " mph", (114, 0))
|
||||||
write_text(50, 35, Temperature + " °F", (334, 0))
|
|
||||||
write_text(100, 35, windspeed+" mph", (114, 0))
|
|
||||||
|
|
||||||
if hours == "24":
|
if hours == "24":
|
||||||
sunrisetime = str(datetime.fromtimestamp(int(weather.get_sunrise_time(timeformat='unix'))).strftime('%H:%M'))
|
sunrisetime = str(forecast.sunrise.strftime('%H:%M'))
|
||||||
sunsettime = str(datetime.fromtimestamp(int(weather.get_sunset_time(timeformat='unix'))).strftime('%H:%M'))
|
sunsettime = str(forecast.sunset.strftime('%H:%M'))
|
||||||
|
|
||||||
if hours == "12":
|
if hours == "12":
|
||||||
sunrisetime = str(datetime.fromtimestamp(int(weather.get_sunrise_time(timeformat='unix'))).strftime('%I:%M'))
|
sunrisetime = str(forecast.sunrise.strftime('%I:%M'))
|
||||||
sunsettime = str(datetime.fromtimestamp(int(weather.get_sunset_time(timeformat='unix'))).strftime('%I:%M'))
|
sunsettime = str(forecast.sunset.strftime('%I:%M'))
|
||||||
|
|
||||||
print('Temperature: '+Temperature+' °C')
|
print('Temperature: ' + forecast.air_temperature + ' °C')
|
||||||
print('Humidity: '+Humidity+'%')
|
print('Humidity: ' + forecast.air_humidity + '%')
|
||||||
print('Icon code: '+weathericon)
|
print('Icon code: ' + forecast.icon)
|
||||||
print('weather-icon name: '+weathericons[weathericon])
|
print('weather-icon name: ' + weathericons[forecast.icon])
|
||||||
print('Wind speed: '+windspeed+'km/h')
|
print('Wind speed: ' + forecast.wind_speed + 'km/h')
|
||||||
print('Sunrise-time: ' + sunrisetime)
|
print('Sunrise-time: ' + sunrisetime)
|
||||||
print('Sunset time: ' + sunsettime)
|
print('Sunset time: ' + sunsettime)
|
||||||
print('Cloudiness: ' + cloudstatus+'%')
|
print('Cloudiness: ' + forecast.clouds + '%')
|
||||||
print('Weather description: '+weather_description+'\n')
|
print('Short weather description: ' + forecast.short_description)
|
||||||
|
print('Detailed weather description: ' + forecast.detailed_description + '\n')
|
||||||
|
|
||||||
"""Drawing the fetched weather icon"""
|
"""Drawing the fetched weather icon"""
|
||||||
image.paste(im_open(wpath+weathericons[weathericon]+'.jpeg'), wiconplace)
|
image.paste(im_open(wpath + weathericons[forecast.icon] + '.jpeg'), wiconplace)
|
||||||
|
|
||||||
"""Drawing the fetched temperature"""
|
"""Drawing the fetched temperature"""
|
||||||
image.paste(tempicon, tempplace)
|
image.paste(tempicon, tempplace)
|
||||||
|
|
||||||
"""Drawing the fetched humidity"""
|
"""Drawing the fetched humidity"""
|
||||||
image.paste(humicon, humplace)
|
image.paste(humicon, humplace)
|
||||||
write_text(50, 35, Humidity + " %", (334, 35))
|
write_text(50, 35, forecast.air_humidity + " %", (334, 35))
|
||||||
|
|
||||||
"""Drawing the fetched sunrise time"""
|
"""Drawing the fetched sunrise time"""
|
||||||
image.paste(sunriseicon, sunriseplace)
|
image.paste(sunriseicon, sunriseplace)
|
||||||
|
@ -183,7 +177,7 @@ def main():
|
||||||
image.paste(windicon, windiconspace)
|
image.paste(windicon, windiconspace)
|
||||||
|
|
||||||
"""Write a short weather description"""
|
"""Write a short weather description"""
|
||||||
write_text(144, 35, weather_description, (70, 35))
|
write_text(144, 35, forecast.short_description, (70, 35))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
image.paste(no_response, wiconplace)
|
image.paste(no_response, wiconplace)
|
||||||
|
@ -194,7 +188,8 @@ def main():
|
||||||
upcoming = []
|
upcoming = []
|
||||||
for icalendars in ical_urls:
|
for icalendars in ical_urls:
|
||||||
decode = str(urlopen(icalendars).read().decode())
|
decode = str(urlopen(icalendars).read().decode())
|
||||||
#fix a bug related to Alarm action by replacing parts of the icalendar
|
#fix a bug related to Alarm action by replacing parts of the
|
||||||
|
#icalendar
|
||||||
fix_e = decode.replace('BEGIN:VALARM\r\nACTION:NONE','BEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:')
|
fix_e = decode.replace('BEGIN:VALARM\r\nACTION:NONE','BEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:')
|
||||||
#uncomment line below to display your calendar in ical format
|
#uncomment line below to display your calendar in ical format
|
||||||
#print(fix_e)
|
#print(fix_e)
|
||||||
|
|
Loading…
Reference in a new issue