Skip to content

Commit

Permalink
Merge pull request #304 from opencivicdata/patch/hec/metro/fix-compar…
Browse files Browse the repository at this point in the history
…ison

Fix English and Spanish event pairing in Metro scraper
  • Loading branch information
hancush authored Dec 3, 2019
2 parents a637523 + cbaec0d commit cd1877e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lametro/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,21 @@ def api_events(self, *args, **kwargs):
# be included in the our partial scrape and the other
# member won't be. So, we try to find the partners for
# unpaired events.

#
# Spanish broadcasting didn't start until 5/16/2018, so we
# check the date of any unpaired events to make sure they
# should have a pair.

spanish_start_date = datetime.datetime(2018, 5, 15, 0, 0, 0, 0)
if partial_scrape:
partner_event = self._find_partner(unpaired_event)

spanish_start_date = datetime.datetime(2018, 5, 15, 0, 0, 0, 0)
event_date = datetime.datetime.strptime(unpaired_event['EventDate'], '%Y-%m-%dT%H:%M:%S')

if partner_event is not None:
yield partner_event
elif unpaired_event['EventDate'] > spanish_start_date:

elif event_date > spanish_start_date and unpaired_event.is_spanish:
raise UnmatchedEventError(unpaired_event)

def _merge_events(self, events):
Expand Down Expand Up @@ -179,7 +183,7 @@ def scrape(self, window=None) :
else:
n_days_ago = None

events = self.events(n_days_ago)
events = self.events(since_datetime=n_days_ago)

for event, web_event in self._merge_events(events):
body_name = event["EventBodyName"]
Expand Down

0 comments on commit cd1877e

Please sign in to comment.