Skip to content

Commit

Permalink
Bugfix...
Browse files Browse the repository at this point in the history
State didn't update since I removed the repeated scraping.
  • Loading branch information
J-Lindvig authored Jan 26, 2022
1 parent d8e6fb9 commit e912efe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/flagdays_dk/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
UTC_FORMAT = '%Y-%m-%dT%H:%M:%S%z'

CREDITS = [
{ 'Created by': 'J-Lindvig (https://github.com/J-Lindvig' },
{ 'Created by': 'J-Lindvig (https://github.com/J-Lindvig)' },
{ 'Data provided by': 'Justitsministeriet (' + FLAGDAY_URL + ')' },
{ 'Sunrise/sunset provided by': 'Sunrise-Sunset (https://sunrise-sunset.org/api)' }
]
11 changes: 9 additions & 2 deletions custom_components/flagdays_dk/flagdays.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self, custom_events = None, flags = None, coordinates = DEFAULT_COO
_LOGGER.debug("[flags] : " + str(self._flags))

def getFlagdays(self):
self._now = datetime.now()
# It the events are empty, fetch data from the site
if not self._events:
self._session = requests.Session()
Expand Down Expand Up @@ -114,9 +115,15 @@ def getFlagdays(self):
# Loop through the given events from the configuration.yaml
for event in self._custom_events:
self._events.append(self._getCustomEvent(event))

# Sort the events
self._events = sorted(self._events, key=lambda d: d['timestamp'])
self._events = sorted(self._events, key=lambda d: d['timestamp'])
else:
for i in range(len(self._events)):
# Create a Date object from the date of the event
dateObj = self._getDateObjectFromFlag(self._events[i])
# Calculate days to the event
self._events[i]['days_to_event'] = (dateObj - self._now).days + 1

# Find the firstcoming event
self._next_event = self._getNextEvent()
Expand Down
2 changes: 1 addition & 1 deletion custom_components/flagdays_dk/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"codeowners": ["J-Lindvig"],
"requirements": ["beautifulsoup4", "html.parser"],
"iot_class": "cloud_polling",
"version": "1.3"
"version": "1.4"
}

0 comments on commit e912efe

Please sign in to comment.