Skip to content

Commit be6a938

Browse files
committed
Cleaning up the loading of ics
1 parent 4e7c273 commit be6a938

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

calcure/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from calcure.translations.en import *
4040

4141

42-
__version__ = "2.8.1"
42+
__version__ = "2.8.2"
4343

4444

4545
def read_items_from_user_arguments(screen, user_tasks, user_events, task_saver_csv, event_saver_csv):

calcure/loaders.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,15 @@ def read_lines(self, file):
229229
for line in file:
230230
# If there is more than one PRODID line or a TZUNTIL line, skip them:
231231
if (not ("PRODID:" in line and "PRODID:" in previous_line) and
232-
not ("TZUNTIL" in line)):
232+
not ("TZUNTIL" in line)):
233233
text += line
234234
previous_line = line
235235
return text
236236

237237
def read_file(self, path):
238238
"""Parse an ics file if it exists"""
239239
if not os.path.exists(path):
240-
logging.error("Failed to load %s. Probably path is incorrect.", path)
240+
logging.error("Failed to load %s because file does not exist.", path)
241241
return ""
242242
with open(path, 'r', encoding="utf-8") as file:
243243
return self.read_lines(file)
@@ -249,10 +249,10 @@ def read_url(self, path):
249249
file = io.TextIOWrapper(response, 'utf-8')
250250
return self.read_lines(file)
251251
except urllib.error.HTTPError:
252-
logging.error("Failed to load %s. Probably url is wrong.", path)
252+
logging.error("Failed to load from %s. Probably url is wrong.", path)
253253
return ""
254254
except urllib.error.URLError:
255-
logging.error("Failed to load %s. Probably no internet connection.", path)
255+
logging.error("Failed to load from %s. Probably no internet connection.", path)
256256
return ""
257257

258258
def read_resource(self, path):
@@ -337,12 +337,8 @@ def load(self):
337337
year, month, day, calendar_number)
338338
self.user_ics_tasks.add_item(new_task)
339339

340-
except NotImplementedError: # More than one calendar in the file
341-
logging.error("Failed to load %s. Probably more that one calendar in this file.", filename)
342-
pass
343340
except Exception:
344-
logging.error("Failed to load %s.", filename)
345-
pass
341+
logging.error("Failed to parse %s.", filename)
346342
return self.user_ics_tasks
347343

348344

@@ -402,11 +398,7 @@ def load(self):
402398
frequency, status, is_private, calendar_number)
403399
self.user_ics_events.add_item(new_event)
404400

405-
except NotImplementedError: # More than one calendar in the file
406-
logging.error("Failed to load %s. Probably more that one calendar in this file", filename)
407-
pass
408401
except Exception:
409-
logging.error("Failed to load %s.", filename)
410-
pass
402+
logging.error("Failed to parse %s.", filename)
411403

412404
return self.user_ics_events

0 commit comments

Comments
 (0)