Skip to content

Commit

Permalink
Added handling for cases where a start time is not present for an eve…
Browse files Browse the repository at this point in the history
…nt in the calendar feed.
  • Loading branch information
bbusenius committed Oct 16, 2024
1 parent 0ccae79 commit 3986f7c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def get_entries_from_events_uchicago(x):
guid = entry.find('link').text

start_date = entry.find('startDate').text.strip()
start_time = entry.find('startTime').text.strip()
start_time = entry.find('startTime').text

if start_time:
start_time = start_time.strip()
else:
start_time = ''

end_date = ''
sortable_end_date = ''
Expand All @@ -56,11 +61,14 @@ def get_entries_from_events_uchicago(x):
end_time = entry.find('endTime').text.strip()

sortable_date = datetime.strptime(start_date, '%b %d, %Y').strftime('%Y-%m-%d')
sortable_datetime = (
sortable_date
+ ' '
+ datetime.strptime(start_time, '%I:%M %p').strftime('%H:%M')
)
try:
sortable_datetime = (
sortable_date
+ ' '
+ datetime.strptime(start_time, '%I:%M %p').strftime('%H:%M')
)
except (ValueError):
sortable_datetime = (sortable_date + ' ' + '')

start_date_short_form = datetime.strptime(start_date, '%b %d, %Y').strftime(
'%m/%d'
Expand Down

0 comments on commit 3986f7c

Please sign in to comment.