Added connectivity check in iCalendar section
This commit is contained in:
		| @@ -91,6 +91,13 @@ def main(): | ||||
|                 ImageDraw.Draw(space).text((x, y), text, fill='black', font=font) | ||||
|                 image.paste(space, tuple) | ||||
|  | ||||
|             def internet_available(): | ||||
|                 try: | ||||
|                     urlopen('https://google.com',timeout=5) | ||||
|                     return True | ||||
|                 except URLError as err: | ||||
|                     return False | ||||
|  | ||||
|             """Connect to Openweathermap API and fetch weather data""" | ||||
|             if top_section is "Weather" and api_key != "" and owm.is_API_online() is True: | ||||
|                 print("Connecting to Openweathermap API servers...") | ||||
| @@ -278,7 +285,6 @@ def main(): | ||||
|             if middle_section is "Calendar" or "Agenda": | ||||
|                 """Algorithm for filtering and sorting events from your | ||||
|                 iCalendar/s""" | ||||
|                 print('Fetching events from your calendar'+'\n') | ||||
|                 events_this_month = [] | ||||
|                 upcoming = [] | ||||
|                 now = arrow.now() | ||||
| @@ -288,6 +294,9 @@ def main(): | ||||
|                 to filter events in that range""" | ||||
|                 agenda_max_days = arrow.now().replace(days=+22) | ||||
|                 calendar_max_days = arrow.now().replace(days=+int(events_max_range)) | ||||
|                 if internet_available() is True: | ||||
|                     print('Internet connection test passed'+'\n') | ||||
|                     print('Fetching events from your calendar'+'\n') | ||||
|                     for icalendars in ical_urls: | ||||
|                         decode = str(urlopen(icalendars).read().decode()) | ||||
|                         beginAlarmIndex = 0 | ||||
| @@ -327,6 +336,11 @@ def main(): | ||||
|  | ||||
|                     upcoming.sort(key=event_begins) | ||||
|  | ||||
|                 else: | ||||
|                     print("Could not fetch events from your iCalendar.") | ||||
|                     print("Either the internet connection is too slow or we're offline.") | ||||
|  | ||||
|  | ||||
|                 if middle_section is 'Agenda': | ||||
|                     """For the agenda view, create a list containing dates and events of the next 22 days""" | ||||
|                     if len(upcoming) is not 0: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user