def getMatches(self, event_key): year = int(event_key[:4]) event_short = event_key[4:] hs_parser = FMSAPIHybridScheduleParser(year, event_short) detail_parser = FMSAPIMatchDetailsParser(year, event_short) qual_matches = self._parse( self.FMS_API_HYBRID_SCHEDULE_QUAL_URL_PATTERN % (year, self._get_event_short(event_short)), hs_parser) playoff_matches = self._parse( self.FMS_API_HYBRID_SCHEDULE_PLAYOFF_URL_PATTERN % (year, self._get_event_short(event_short)), hs_parser) qual_details = self._parse( self.FMS_API_MATCH_DETAILS_QUAL_URL_PATTERN % (year, self._get_event_short(event_short)), detail_parser) playoff_details = self._parse( self.FMS_API_MATCH_DETAILS_PLAYOFF_URL_PATTERN % (year, self._get_event_short(event_short)), detail_parser) matches_by_key = {} if qual_matches is not None: for match in qual_matches: matches_by_key[match.key.id()] = match if playoff_matches is not None: for match in playoff_matches: matches_by_key[match.key.id()] = match for match_key, match_details in qual_details.items( ) + playoff_details.items(): if match_key in matches_by_key: matches_by_key[match_key].score_breakdown_json = json.dumps( match_details) return matches_by_key.values()
def getMatches(self, event_key): year = int(event_key[:4]) event_short = event_key[4:] event = Event.get_by_id(event_key) hs_parser = FMSAPIHybridScheduleParser(year, event_short) detail_parser = FMSAPIMatchDetailsParser(year, event_short) qual_matches_future = self._parse_async(self.FMS_API_HYBRID_SCHEDULE_QUAL_URL_PATTERN % (year, self._get_event_short(event_short, event)), hs_parser) playoff_matches_future = self._parse_async(self.FMS_API_HYBRID_SCHEDULE_PLAYOFF_URL_PATTERN % (year, self._get_event_short(event_short, event)), hs_parser) qual_details_future = self._parse_async(self.FMS_API_MATCH_DETAILS_QUAL_URL_PATTERN % (year, self._get_event_short(event_short, event)), detail_parser) playoff_details_future = self._parse_async(self.FMS_API_MATCH_DETAILS_PLAYOFF_URL_PATTERN % (year, self._get_event_short(event_short, event)), detail_parser) matches_by_key = {} qual_matches = qual_matches_future.get_result() if qual_matches is not None: for match in qual_matches[0]: matches_by_key[match.key.id()] = match playoff_matches = playoff_matches_future.get_result() if playoff_matches is not None: for match in playoff_matches[0]: matches_by_key[match.key.id()] = match qual_details = qual_details_future.get_result() qual_details_items = qual_details.items() if qual_details is not None else [] playoff_details = playoff_details_future.get_result() playoff_details_items = playoff_details.items() if playoff_details is not None else [] for match_key, match_details in qual_details_items + playoff_details_items: match_key = playoff_matches[1].get(match_key, match_key) if match_key in matches_by_key: matches_by_key[match_key].score_breakdown_json = json.dumps(match_details) return filter( lambda m: not FMSAPIHybridScheduleParser.is_blank_match(m), matches_by_key.values())