Preparing for v1.4!
This commit is contained in:
		| @@ -8,7 +8,7 @@ If you have any questions, feel free to open an issue at Github. | |||||||
|  |  | ||||||
| Copyright by Ace-Laboratory | Copyright by Ace-Laboratory | ||||||
| """ | """ | ||||||
| print('importing modules'+'\n') | print('importing modules') | ||||||
| from settings import * | from settings import * | ||||||
| from icon_positions_locations import * | from icon_positions_locations import * | ||||||
|  |  | ||||||
| @@ -17,9 +17,13 @@ import calendar,  pyowm | |||||||
| from ics import Calendar, Event | from ics import Calendar, Event | ||||||
| from datetime import datetime | from datetime import datetime | ||||||
| from time import sleep | from time import sleep | ||||||
|  | try: | ||||||
|     from urllib.request import urlopen |     from urllib.request import urlopen | ||||||
|  | except Exception as e: | ||||||
|  |     print('It seems the network is offline :(') | ||||||
|  |     pass | ||||||
| import arrow | import arrow | ||||||
|  | print('modules imported successfully!'+'\n') | ||||||
|  |  | ||||||
| if display_colours == "bwr": | if display_colours == "bwr": | ||||||
|     import epd7in5b |     import epd7in5b | ||||||
| @@ -31,12 +35,11 @@ if display_colours == "bw": | |||||||
|     epd = epd7in5.EPD() |     epd = epd7in5.EPD() | ||||||
|     from calibration_bw import calibration |     from calibration_bw import calibration | ||||||
|  |  | ||||||
| font = ImageFont.truetype(path+'Assistant-Bold.ttf', 18) |  | ||||||
| c = Calendar(urlopen(url).read().decode('UTF-8')) | c = Calendar(urlopen(url).read().decode('UTF-8')) | ||||||
| e = Event() | e = Event() | ||||||
| EPD_WIDTH = 640 | EPD_WIDTH = 640 | ||||||
| EPD_HEIGHT = 384 | EPD_HEIGHT = 384 | ||||||
|  | font = ImageFont.truetype(path+'Assistant-Bold.ttf', 18) | ||||||
|  |  | ||||||
| def main(): | def main(): | ||||||
|     while True: |     while True: | ||||||
| @@ -48,7 +51,7 @@ def main(): | |||||||
|             """At the following hours (midnight, midday and 6 pm), perform |             """At the following hours (midnight, midday and 6 pm), perform | ||||||
|                a calibration of the display's colours""" |                a calibration of the display's colours""" | ||||||
|             if (hour is 0) or (hour is 12) or (hour is 18): |             if (hour is 0) or (hour is 12) or (hour is 18): | ||||||
|                 print('performing calibration now') |                 print('performing calibration for colours now') | ||||||
|                 calibration() |                 calibration() | ||||||
|  |  | ||||||
|             print('Current date:',time.strftime('%a %-d %b %y')) |             print('Current date:',time.strftime('%a %-d %b %y')) | ||||||
| @@ -97,10 +100,23 @@ def main(): | |||||||
|             except IndexError: |             except IndexError: | ||||||
|                 pass |                 pass | ||||||
|  |  | ||||||
|  |  | ||||||
|  |             def write_text(a,b, text, c,d):#a,b box-size  #c,d box position | ||||||
|  |                 w, h = font.getsize(text) | ||||||
|  |                 if (w, h) > (a, b): | ||||||
|  |                     raise ValueError('Sorry, your text is too big for the box') | ||||||
|  |                 else: | ||||||
|  |                     x = int((a / 2) - (w / 2)) | ||||||
|  |                     y = int((b / 2) - (h / 2)) | ||||||
|  |                     space = Image.new('1', (a,b), color=255) | ||||||
|  |                     ImageDraw.Draw(space).text((x, y), text,  fill=0 ,font=font) | ||||||
|  |                     image.paste(space.rotate(270,  expand=1), (c,d)) | ||||||
|  |  | ||||||
|  |  | ||||||
|             """ Handling Openweathermap API""" |             """ Handling Openweathermap API""" | ||||||
|             try: |  | ||||||
|                 print("Preparing to fetch data from openweathermap API") |  | ||||||
|             owm = pyowm.OWM(api_key) |             owm = pyowm.OWM(api_key) | ||||||
|  |             if owm.is_API_online() is True: #test server connection | ||||||
|  |                 print("Preparing to fetch data from openweathermap API") | ||||||
|                 observation = owm.weather_at_place(location) |                 observation = owm.weather_at_place(location) | ||||||
|                 print("Fetching weather data...") |                 print("Fetching weather data...") | ||||||
|                 weather = observation.get_weather() |                 weather = observation.get_weather() | ||||||
| @@ -108,58 +124,67 @@ def main(): | |||||||
|  |  | ||||||
|                 Temperature = str(int(weather.get_temperature(unit='celsius')['temp'])) |                 Temperature = str(int(weather.get_temperature(unit='celsius')['temp'])) | ||||||
|                 Humidity = str(weather.get_humidity()) |                 Humidity = str(weather.get_humidity()) | ||||||
|                 print('temperature: '+Temperature +' °C') |                 print('temperature: '+Temperature +' °C') | ||||||
|                 print('humidity: '+Humidity+'%') |                 print('humidity: '+Humidity+'%') | ||||||
|                 print('fetched icon code: '+weathericon) |                 print('fetched icon code: '+weathericon) | ||||||
|                 print('equivalent to icon: '+weathericons[weathericon]+'\n') |                 print('equivalent to icon: '+weathericons[weathericon]+'\n') | ||||||
|  |                 windspeed= str(int(weather.get_wind()['speed'])) | ||||||
|  |                 sunrisetime = str(datetime.fromtimestamp(int(weather.get_sunrise_time(timeformat='unix'))).strftime('%H:%M')) | ||||||
|  |                 sunsettime = str(datetime.fromtimestamp(int(weather.get_sunset_time(timeformat='unix'))).strftime('%H:%M')) | ||||||
|  |                 cloudstatus = str(weather.get_clouds()) | ||||||
|  |                 weather_description = (str(weather.get_status())) | ||||||
|  |                 print('Current wind speed: '+windspeed+ 'km/h') | ||||||
|  |                 print('The sunrise today took take place place at: '+sunrisetime) | ||||||
|  |                 print('The sunset today will take place place at: '+sunsettime) | ||||||
|  |                 print('The current Cloud condition is: ' + cloudstatus + '%') | ||||||
|  |                 print('Weather: '+ weather_description) | ||||||
|  |  | ||||||
|                 """Drawing the fetched weather icon""" |                 """Drawing the fetched weather icon""" | ||||||
|                 draw(wiconplace, open(wpath+weathericons[weathericon] + '.bmp')) |                 draw(wiconplace, open(wpath+weathericons[weathericon] + '.bmp')) | ||||||
|  |  | ||||||
|                 """Drawing the fetched temperature""" |                 """Drawing the fetched temperature""" | ||||||
|                 space2 = Image.new('1', (50,35), color=255) |                 draw(tempplace, tempicon) | ||||||
|                 temperature = ImageDraw.Draw(space2) |                 write_text(50,35, Temperature + " °C", 605, 334) | ||||||
|                 temperature.text((2, 8), (Temperature + " °C"),  fill=0 ,font=font) |  | ||||||
|                 rotate2 = space2.rotate(270,  expand=1) |  | ||||||
|                 image.paste(rotate2, (605,334)) |  | ||||||
|  |  | ||||||
|                 """Drawing the fetched humidity""" |                 """Drawing the fetched humidity""" | ||||||
|                 space3 = Image.new('1', (50,35), color=255) |                 draw(humplace, humicon) | ||||||
|                 humidity = ImageDraw.Draw(space3) |                 write_text(50,35, Humidity + " %", 570, 334) | ||||||
|                 humidity.text((4, 8), (Humidity +'%'),  fill=0 ,font=font) |  | ||||||
|                 rotate3 = space3.rotate(270,  expand=1) |  | ||||||
|                 image.paste(rotate3, (570,334)) |  | ||||||
|  |  | ||||||
|             except Exception as e: |                 """Drawing the fetched sunrise time""" | ||||||
|                 template = "An exception of type {0} occurred. Arguments:\n{1!r}" |                 draw(sunriseplace, sunriseicon) | ||||||
|                 message = template.format(type(ex).__name__, ex.args) |                 write_text(50,35, sunrisetime, 605, 250) | ||||||
|                 print(message) |  | ||||||
|                 print("************ OWM DID NOT RESPOND *************") |                 """Drawing the fetched sunset time""" | ||||||
|                 print("Drawing the 'no-response' icon on the display now") |                 draw(sunsetplace, sunseticon) | ||||||
|  |                 write_text(50,35, sunsettime, 570, 250) | ||||||
|  |  | ||||||
|  |                 """Drawing the fetched wind speed""" | ||||||
|  |                 draw(windiconspace, windicon) | ||||||
|  |                 write_text(75, 35, windspeed+" km/h", 605,135) | ||||||
|  |  | ||||||
|  |                 """Write a short weather description""" | ||||||
|  |                 write_text(100,35, weather_description, 570, 100) | ||||||
|  |  | ||||||
|  |             else: | ||||||
|                 draw(wiconplace, no_response) |                 draw(wiconplace, no_response) | ||||||
|                 pass |                 pass | ||||||
|  |  | ||||||
|             """Drawing today's date at the top left corner""" |  | ||||||
|             """Uncomment this section (the following 5 lines) to hide date at top left corner""" |  | ||||||
|             space1=Image.new('1', (115,25), color=255) |  | ||||||
|             date = ImageDraw.Draw(space1) |  | ||||||
|             date.text((2, 3), (time.strftime('%a %-d %b %y')),  font=font, fill=0) |  | ||||||
|             rotate1 = space1.rotate(270,  expand=1) |  | ||||||
|             image.paste(rotate1, (595,20)) |  | ||||||
|  |  | ||||||
|             """Sort the Events in your iCalendar""" |             """Sort the Events in your iCalendar""" | ||||||
|             print('Fetching upcoming events from your calendar') |             print('Fetching upcoming events from your calendar') | ||||||
|             elist = [] |             elist = [] | ||||||
|  |             eventstoday = [] | ||||||
|             for events in c.events: |             for events in c.events: | ||||||
|                 if time.year <= int((events.begin).format('YYYY')): |                 if time.year <= int((events.begin).format('YYYY')): | ||||||
|                     if time.month == int((events.begin).format('M')): |                     if time.month == int((events.begin).format('M')): | ||||||
|                         elist.append(int((events.begin).format('D'))) |                         elist.append(int((events.begin).format('D'))) | ||||||
|  |  | ||||||
|             """Uncomment the next 4 lines to print your events on the console""" |             """Uncomment the next 4 lines to print your events on the console""" | ||||||
| #                        if time.day <= int((events.begin).format('D')): | #                        if time.day <= int((events.begin).format('D')): | ||||||
| #                           print(events.name+' starts on '+events.begin.format('D '+'MMM '+'YYYY')) | #                           print(events.name+' starts on '+events.begin.format('D '+'MMM '+'YYYY')) | ||||||
| #                    if time.month < int((events.begin).format('M')): | #                    if time.month < int((events.begin).format('M')): | ||||||
| #                        print(events.name+' starts on '+events.begin.format('D '+'MMM '+'YYYY')) | #                        print(events.name+' starts on '+events.begin.format('D '+'MMM '+'YYYY')) | ||||||
|  |  | ||||||
|  |                              | ||||||
|             """Draw circles on any days which include an Event""" |             """Draw circles on any days which include an Event""" | ||||||
|             for x in elist: |             for x in elist: | ||||||
|                 if x in cal[0]: |                 if x in cal[0]: | ||||||
| @@ -178,7 +203,6 @@ def main(): | |||||||
|                 except IndexError: |                 except IndexError: | ||||||
|                     pass |                     pass | ||||||
|  |  | ||||||
|  |  | ||||||
|             """Draw a square with round corners on the today's date""" |             """Draw a square with round corners on the today's date""" | ||||||
|             today = time.day |             today = time.day | ||||||
|             if today in cal[0]: |             if today in cal[0]: | ||||||
| @@ -197,9 +221,6 @@ def main(): | |||||||
|             except IndexError: |             except IndexError: | ||||||
|                     pass |                     pass | ||||||
|  |  | ||||||
|             draw(tempplace, tempicon) |  | ||||||
|             draw(humplace, humicon) |  | ||||||
|  |  | ||||||
|             print('\n'+'initialising E-Paper Display') |             print('\n'+'initialising E-Paper Display') | ||||||
|             epd.init() |             epd.init() | ||||||
|             sleep(5) |             sleep(5) | ||||||
| @@ -208,6 +229,7 @@ def main(): | |||||||
|  |  | ||||||
|             # delete the list so deleted events can be removed from the list |             # delete the list so deleted events can be removed from the list | ||||||
|             del elist[:] |             del elist[:] | ||||||
|  |             del eventstoday[:] | ||||||
|             print('data sent successfully'+'\n') |             print('data sent successfully'+'\n') | ||||||
|             print('letting the display sleep until the next hour') |             print('letting the display sleep until the next hour') | ||||||
|             epd.sleep() |             epd.sleep() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user