Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion custom_components/isc/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _load_data(url):
"""Load data from URL, exported to const to call it from sensor and from config_flow."""
if(url.lower().startswith("file://")):
req = Request(url=url, data=None, headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'})
return urlopen(req).read().decode('ISO-8859-1')
return urlopen(req).read().decode('UTF-8')
return requests.get(url, headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'}, allow_redirects=True).content

async def async_load_data(hass, url):
Expand Down
21 changes: 7 additions & 14 deletions custom_components/isc/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ def icon(self):
"""Return the icon to use in the frontend."""
return self._icon

def fix_text(self, s):
"""Remove Umlaute."""
s = ''.join(e for e in s if (e.isalnum() or e == ' '))
s = s.replace(chr(195), 'u')
s = s.replace(chr(188), 'e')
return s

def exc(self):
"""Print nicely formated exception."""
_LOGGER.error("\n\n============= ICS Integration Error ================")
Expand Down Expand Up @@ -231,14 +224,14 @@ async def get_data(self):
event_end_date = event_date

# handle empty or non existing summary field
event_summary = self.fix_text(self._show_blank)
event_summary = self._show_blank
if("SUMMARY" in e):
if(self.fix_text(e["SUMMARY"]) != ""):
event_summary = self.fix_text(e["SUMMARY"])
if(e.get("SUMMARY") != ""):
event_summary = e["SUMMARY"]

if(event_summary):
if(event_summary.lower().startswith(self.fix_text(self._sw).lower()) and
event_summary.lower().find(self.fix_text(self._contains).lower())>=0 and
if(event_summary.lower().startswith(self._sw.lower()) and
event_summary.lower().find(self._contains.lower())>=0 and
self.matches_regex(event_summary)):
if((event_date > now) or (self._show_ongoing and event_end_date > now)):
# logic to skip events, but save certain details,
Expand Down Expand Up @@ -267,14 +260,14 @@ async def get_data(self):
self.ics['extra']['start'] = event_date.astimezone()
self.ics['extra']['end'] = event_end_date.astimezone()
if("LOCATION" in e):
self.ics['extra']['location'] = self.fix_text(e["LOCATION"])
self.ics['extra']['location'] = e["LOCATION"]
et = event_date

# if grouping is active and we hat it again, append
elif((event_date == et) and (self._group_events)):
self.ics['extra']['description'] += " / " + event_summary
if("LOCATION" in e):
self.ics['extra']['location'] += " / " + self.fix_text(e["LOCATION"])
self.ics['extra']['location'] += " / " + e["LOCATION"]
# store earliest end time
if(self.ics['extra']['end'] > e["DTEND"].dt):
self.ics['extra']['end'] = e["DTEND"].dt.astimezone()
Expand Down