def get_tutorial_search_highlights(fb_id, team): highlights = latest_highlight_manager.get_highlights_for_team(team) if highlights == []: # Case no highlight found for the team return create_quick_text_reply_message( NO_HIGHLIGHTS_MESSAGE, [EMOJI_MAGNIFYING_GLASS + ' New search']) if not highlights: # Case no team name matched similar_team_names = football_team_manager.similar_football_team_names( team) similar_team_names = [ team_name.title() for team_name in similar_team_names ] # Check if name of team was not properly written if similar_team_names: return create_quick_text_reply_message( NO_MATCH_FOUND_TEAM_RECOMMENDATION, similar_team_names[:10]) else: return create_quick_text_reply_message( NO_MATCH_FOUND, [EMOJI_MAGNIFYING_GLASS + ' Search again']) # Eliminate duplicates highlights = latest_highlight_manager.get_unique_highlights(highlights) # Order highlights by date and take the first 10 highlights = sorted(highlights, key=lambda h: h.get_parsed_time_since_added(), reverse=True)[:10] return create_generic_attachment(highlights_to_json(fb_id, highlights))
def send_highlights_for_team_or_competition(fb_id, team_or_competition, highlight_count=10, default_teams=[]): highlights = latest_highlight_manager.get_highlights_for_team_or_competition( team_or_competition) if highlights == []: # Case no highlight found for the team_or_competition if not default_teams: return send_no_highlight_found_message(fb_id) # as fallback, use example such as PSG, Barcelona, Real Madrid, Spain or France for team in default_teams: highlights += latest_highlight_manager.get_highlights_for_team_or_competition( team) if highlights != []: break # Eliminate duplicates highlights = latest_highlight_manager.get_unique_highlights( highlights, max_count=highlight_count) # Check if user has see result activated see_result_setting = user_manager.get_see_result_setting(fb_id) return send_facebook_message( fb_id, create_generic_attachment( highlights_to_json(fb_id, highlights, see_result=see_result_setting)))
def get_highlights_for_team(fb_id, team, highlight_count=10): highlights = latest_highlight_manager.get_highlights_for_team(team) if highlights == []: # Case no highlight found for the team return create_quick_text_reply_message( NO_HIGHLIGHTS_MESSAGE, [SEARCH_AGAIN_HIGHLIGHTS_BUTTON, HELP_BUTTON, CANCEL_BUTTON]) if not highlights: # Case no team name matched similar_team_names = football_team_manager.similar_football_team_names( team) # Register wrong search new_football_registration_manager.add_football_registration( team, 'user') # Check if name of team was not properly written if len(similar_team_names) == 0: return create_quick_text_reply_message( NO_MATCH_FOUND, [SEARCH_AGAIN_HIGHLIGHTS_BUTTON, HELP_BUTTON, CANCEL_BUTTON]) elif len(similar_team_names) == 1: # Case where only one team is similar, so send the highlights for this team # -> error correction as user might have done a typo team = similar_team_names[0] highlights = latest_highlight_manager.get_highlights_for_team(team) elif len(similar_team_names) >= 2: similar_team_names = [ team_name.title() for team_name in similar_team_names ] return create_quick_text_reply_message( NO_MATCH_FOUND_TEAM_RECOMMENDATION, similar_team_names[:9] + [HELP_BUTTON, CANCEL_BUTTON]) # Eliminate duplicates highlights = latest_highlight_manager.get_unique_highlights(highlights) # Order highlights by date and take the first 10 highlights = sorted(highlights, key=lambda h: h.get_parsed_time_since_added(), reverse=True)[:highlight_count] # Check if user has see result activated see_result_setting = user_manager.get_see_result_setting(fb_id) return create_generic_attachment( highlights_to_json(fb_id, highlights, see_result=see_result_setting))
def send_tutorial_highlight(fb_id, team): highlights = latest_highlight_manager.get_highlights_for_team(team) if highlights == []: # Case no highlight found for the team, use example such as PSG, Barcelona, Real Madrid highlights = latest_highlight_manager.get_highlights_for_team('psg') \ + latest_highlight_manager.get_highlights_for_team('barcelona') \ + latest_highlight_manager.get_highlights_for_team('real madrid') # Eliminate duplicates highlights = latest_highlight_manager.get_unique_highlights(highlights) # Order highlights by date and take the first one highlight = sorted(highlights, key=lambda h: h.get_parsed_time_since_added(), reverse=True)[0] return send_facebook_message(fb_id, create_generic_attachment(highlights_to_json(fb_id, [highlight])))