Skip to content

Commit

Permalink
Cleaning up the loading of ics
Browse files Browse the repository at this point in the history
  • Loading branch information
anufrievroman committed Mar 4, 2023
1 parent 4e7c273 commit be6a938
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion calcure/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from calcure.translations.en import *


__version__ = "2.8.1"
__version__ = "2.8.2"


def read_items_from_user_arguments(screen, user_tasks, user_events, task_saver_csv, event_saver_csv):
Expand Down
20 changes: 6 additions & 14 deletions calcure/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ def read_lines(self, file):
for line in file:
# If there is more than one PRODID line or a TZUNTIL line, skip them:
if (not ("PRODID:" in line and "PRODID:" in previous_line) and
not ("TZUNTIL" in line)):
not ("TZUNTIL" in line)):
text += line
previous_line = line
return text

def read_file(self, path):
"""Parse an ics file if it exists"""
if not os.path.exists(path):
logging.error("Failed to load %s. Probably path is incorrect.", path)
logging.error("Failed to load %s because file does not exist.", path)
return ""
with open(path, 'r', encoding="utf-8") as file:
return self.read_lines(file)
Expand All @@ -249,10 +249,10 @@ def read_url(self, path):
file = io.TextIOWrapper(response, 'utf-8')
return self.read_lines(file)
except urllib.error.HTTPError:
logging.error("Failed to load %s. Probably url is wrong.", path)
logging.error("Failed to load from %s. Probably url is wrong.", path)
return ""
except urllib.error.URLError:
logging.error("Failed to load %s. Probably no internet connection.", path)
logging.error("Failed to load from %s. Probably no internet connection.", path)
return ""

def read_resource(self, path):
Expand Down Expand Up @@ -337,12 +337,8 @@ def load(self):
year, month, day, calendar_number)
self.user_ics_tasks.add_item(new_task)

except NotImplementedError: # More than one calendar in the file
logging.error("Failed to load %s. Probably more that one calendar in this file.", filename)
pass
except Exception:
logging.error("Failed to load %s.", filename)
pass
logging.error("Failed to parse %s.", filename)
return self.user_ics_tasks


Expand Down Expand Up @@ -402,11 +398,7 @@ def load(self):
frequency, status, is_private, calendar_number)
self.user_ics_events.add_item(new_event)

except NotImplementedError: # More than one calendar in the file
logging.error("Failed to load %s. Probably more that one calendar in this file", filename)
pass
except Exception:
logging.error("Failed to load %s.", filename)
pass
logging.error("Failed to parse %s.", filename)

return self.user_ics_events

0 comments on commit be6a938

Please sign in to comment.