From 752dde079fa8c9c6fe94208b830ce38c6bbaa35f Mon Sep 17 00:00:00 2001 From: Jasmine Mithani Date: Wed, 3 Jul 2019 14:43:56 -0500 Subject: [PATCH 1/4] removing time from the partner_key and key --- lametro/events.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lametro/events.py b/lametro/events.py index c32f2645..190aeade 100644 --- a/lametro/events.py +++ b/lametro/events.py @@ -114,7 +114,7 @@ def _merge_events(self, events): if web_event.has_audio: event_audio.append(web_event['Audio']) - matches = spanish_events.get(event.partner_key, None) + matches = spanish_events.pop(event.partner_key, None) if matches: spanish_event, spanish_web_event = matches @@ -155,7 +155,7 @@ def scrape(self, window=None) : else: event_name = body_name - # Events can have an EventAgendaStatusName of "Final", "Final Revised", + # Events can have an EventAgendaStatusName of "Final", "Final Revised", # and "Final 2nd Revised." # We classify these events as "passed." status_name = event['EventAgendaStatusName'] @@ -209,7 +209,7 @@ def scrape(self, window=None) : note = "Agenda number, {}".format(item["EventItemAgendaNumber"]) agenda_item['notes'].append(note) - # The EventItemAgendaSequence provides + # The EventItemAgendaSequence provides # the line number of the Legistar agenda grid. agenda_item['extras']['item_agenda_sequence'] = item['EventItemAgendaSequence'] @@ -222,7 +222,7 @@ def scrape(self, window=None) : {event_name} on {event_date} ({legistar_api_url}). \ Contact Metro, and ask them to remove the duplicate EventItemAgendaSequence.' - raise ValueError(error_msg.format(event_name=e.name, + raise ValueError(error_msg.format(event_name=e.name, event_date=e.start_date.strftime("%B %d, %Y"), legistar_api_url=legistar_api_url)) @@ -329,11 +329,11 @@ def partner_search_string(self): @property def partner_key(self): - return (self._partner_name, self['EventDate'], self['EventTime']) + return (self._partner_name, self['EventDate']) @property def key(self): - return (self['EventBodyName'], self['EventDate'], self['EventTime']) + return (self['EventBodyName'], self['EventDate']) class LAMetroWebEvent(dict): From b244cfbd511395205a6ab856774b0e36e1d14e8b Mon Sep 17 00:00:00 2001 From: Jasmine Mithani Date: Wed, 3 Jul 2019 15:50:28 -0500 Subject: [PATCH 2/4] defensively ensuring keys are not overwritten --- lametro/events.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lametro/events.py b/lametro/events.py index 190aeade..c36badf5 100644 --- a/lametro/events.py +++ b/lametro/events.py @@ -97,6 +97,10 @@ def _merge_events(self, events): web_event = LAMetroWebEvent(web_event) if event.is_spanish: + try: + assert spanish_events.get(event.key, None) == None + except AssertionError: + raise AssertionError('{0} already exists as a key with a value of {1}'.format(event.key, spanish_events[event.key])) spanish_events[event.key] = (event, web_event) else: english_events.append((event, web_event)) From 6b059c3705697746b7efb77f5955df921a5d6ac0 Mon Sep 17 00:00:00 2001 From: Jasmine Mithani Date: Tue, 9 Jul 2019 11:17:20 -0500 Subject: [PATCH 3/4] Condensing assertion with the power of python --- lametro/events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lametro/events.py b/lametro/events.py index c36badf5..c1ff08af 100644 --- a/lametro/events.py +++ b/lametro/events.py @@ -98,7 +98,7 @@ def _merge_events(self, events): if event.is_spanish: try: - assert spanish_events.get(event.key, None) == None + ssert event.key not in spanish_events except AssertionError: raise AssertionError('{0} already exists as a key with a value of {1}'.format(event.key, spanish_events[event.key])) spanish_events[event.key] = (event, web_event) From b5e947c96c09c9aace859ae99ac7ef7136c2b5e8 Mon Sep 17 00:00:00 2001 From: Jasmine Mithani Date: Tue, 9 Jul 2019 11:19:36 -0500 Subject: [PATCH 4/4] ssert assert Co-Authored-By: Hannah Cushman --- lametro/events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lametro/events.py b/lametro/events.py index c1ff08af..37882729 100644 --- a/lametro/events.py +++ b/lametro/events.py @@ -98,7 +98,7 @@ def _merge_events(self, events): if event.is_spanish: try: - ssert event.key not in spanish_events + assert event.key not in spanish_events except AssertionError: raise AssertionError('{0} already exists as a key with a value of {1}'.format(event.key, spanish_events[event.key])) spanish_events[event.key] = (event, web_event)