Update inkycal_agenda.py
This commit is contained in:
		| @@ -5,8 +5,8 @@ Agenda module for Inky-Calendar Project | |||||||
| Copyright by aceisace | Copyright by aceisace | ||||||
| """ | """ | ||||||
| from __future__ import print_function | from __future__ import print_function | ||||||
| from inkycal_icalendar import upcoming_events | from inkycal_icalendar import fetch_events | ||||||
| from configuration import * | from configuration import* | ||||||
| from settings import * | from settings import * | ||||||
| import arrow | import arrow | ||||||
|  |  | ||||||
| @@ -39,10 +39,10 @@ max_lines = int((middle_section_height - border_top*2) // line_height) | |||||||
| line_pos = [(border_left, int(top_section_height + line * line_height)) | line_pos = [(border_left, int(top_section_height + line * line_height)) | ||||||
|   for line in range(max_lines)] |   for line in range(max_lines)] | ||||||
|  |  | ||||||
| draw = ImageDraw.Draw(image) |  | ||||||
|  |  | ||||||
| def main(): | def main(): | ||||||
|   try: |   try: | ||||||
|  |     clear_image('middle_section') | ||||||
|  |                  | ||||||
|     print('Agenda module: Generating image...', end = '') |     print('Agenda module: Generating image...', end = '') | ||||||
|     now = arrow.now() |     now = arrow.now() | ||||||
|  |  | ||||||
| @@ -52,6 +52,7 @@ def main(): | |||||||
|       'type':'date'} for _ in range(max_lines)] |       'type':'date'} for _ in range(max_lines)] | ||||||
|  |  | ||||||
|     """Copy the list from the icalendar module with some conditions""" |     """Copy the list from the icalendar module with some conditions""" | ||||||
|  |     upcoming_events = fetch_events() | ||||||
|     filtered_events = [events for events in upcoming_events if |     filtered_events = [events for events in upcoming_events if | ||||||
|                            events.end.to(get_tz()) > now] |                            events.end.to(get_tz()) > now] | ||||||
|  |  | ||||||
| @@ -79,9 +80,9 @@ def main(): | |||||||
|           agenda_events.append({'date': events.begin,'time':'All day', |           agenda_events.append({'date': events.begin,'time':'All day', | ||||||
|                                 'name': events.name,'type':'full_day_event'}) |                                 'name': events.name,'type':'full_day_event'}) | ||||||
|         else: |         else: | ||||||
|           for days in range(events.duration.days): |           for day in range(events.duration.days): | ||||||
|             agenda_events.append({'date': events.begin.replace(days=+_), |             agenda_events.append({'date': events.begin.replace(days=+day), | ||||||
|               'time':'All day','title':events.name, 'type':'full_day_event'}) |               'time':'All day','name':events.name, 'type':'full_day_event'}) | ||||||
|  |  | ||||||
|     """Sort events and dates in chronological order""" |     """Sort events and dates in chronological order""" | ||||||
|     agenda_events = sorted(agenda_events, key = lambda event: event['date']) |     agenda_events = sorted(agenda_events, key = lambda event: event['date']) | ||||||
| @@ -101,7 +102,7 @@ def main(): | |||||||
|              |              | ||||||
|           previous_date = agenda_events[events]['date']         |           previous_date = agenda_events[events]['date']         | ||||||
|           draw.line((date_col_start, line_pos[events][1], |           draw.line((date_col_start, line_pos[events][1], | ||||||
|             line_width,line_pos[events][1]), fill = 'black') |             line_width,line_pos[events][1]), fill = 'red' if display_type == 'colour' else 'black') | ||||||
|  |  | ||||||
|         elif agenda_events[events]['type'] == 'timed_event': |         elif agenda_events[events]['type'] == 'timed_event': | ||||||
|           write_text(time_col_width, line_height, agenda_events[events]['time'], |           write_text(time_col_width, line_height, agenda_events[events]['time'], | ||||||
| @@ -119,8 +120,7 @@ def main(): | |||||||
|             (event_col_start, line_pos[events][1]), alignment = 'left', font = font) |             (event_col_start, line_pos[events][1]), alignment = 'left', font = font) | ||||||
|  |  | ||||||
|     """Crop the image to show only the middle section""" |     """Crop the image to show only the middle section""" | ||||||
|     agenda_image = image.crop((0, top_section_height, display_width, |     agenda_image = crop_image(image, 'middle_section') | ||||||
|       display_height-bottom_section_height)) |  | ||||||
|     agenda_image.save(image_path+'agenda.png') |     agenda_image.save(image_path+'agenda.png') | ||||||
|     print('Done') |     print('Done') | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user