Exemplo n.º 1
0
    def run_task(self, options):
        for n in mapping_football_team.NAME_MAPPING:
            name = mapping_football_team.NAME_MAPPING[n]

            try:
                team = football_team_manager.get_football_team(name)
                FootballTeamMapping.objects.update_or_create(team_name=n,
                                                             team=team)

                # print(n, team)

            except IndexError:
                print('Error with team: ' + str(n))

        for n in mapping_football_competition.NAME_MAPPING:
            name = mapping_football_competition.NAME_MAPPING[n]

            try:
                competition = football_competition_manager.get_football_competition(
                    name)
                FootballCompetitionMapping.objects.update_or_create(
                    competition_name=n, competition=competition)

                # print(n, competition)

            except IndexError:
                print('Error with competition: ' + str(n))
Exemplo n.º 2
0
def add_highlight(highlight, sent=False):
    # Add team to new team if does not exists and return
    if not has_teams_in_db(highlight):
        add_new_team_to_db(highlight)
        return

    # Add competition to new competition if does not exists and return
    if not has_competition_in_db(highlight):
        add_new_competition_to_db(highlight)
        return

    team1 = football_team_manager.get_football_team(highlight.team1)
    team2 = football_team_manager.get_football_team(highlight.team2)

    category = football_competition_manager.get_football_competition(
        highlight.category)

    LatestHighlight.objects.update_or_create(
        link=highlight.link,
        img_link=highlight.img_link,
        time_since_added=highlight.time_since_added,
        team1=team1,
        score1=highlight.score1,
        team2=team2,
        score2=highlight.score2,
        category=category,
        view_count=highlight.view_count,
        source=highlight.source,
        sent=sent,
        goal_data=highlight.goal_data)
def add_blocked_competition_highlight(team, competition=None):
    team = football_team_manager.get_football_team(team)

    if competition:
        competition = football_competition_manager.get_football_competition(
            competition)

    BlockedNotification.objects.update_or_create(team=team,
                                                 competition=competition)
Exemplo n.º 4
0
def add_highlight(highlight, sent=False):
    # Add team to new team if does not exists and return
    if not has_teams_in_db(highlight):
        add_new_team_to_db(highlight)
        return None

    # Add competition to new competition if does not exists and return
    if not has_competition_in_db(highlight):
        add_new_competition_to_db(highlight)
        return None

    # Run mapping for football team names as team can be named differently
    mapped_team1 = mapping_football_team.get_exact_name(highlight.team1)
    mapped_team2 = mapping_football_team.get_exact_name(highlight.team2)

    team1 = football_team_manager.get_football_team(mapped_team1)
    team2 = football_team_manager.get_football_team(mapped_team2)

    # Run mapping for football competition/category names as they can be named differently
    mapped_competition = mapping_football_competition.get_exact_name(highlight.category)

    category = football_competition_manager.get_football_competition(mapped_competition)

    # Get the match time and id
    match_time = datetime.fromordinal(highlight.time_since_added.date().toordinal())
    id = get_new_id()

    oldest = get_oldest_same_highlight(highlight)

    if oldest:
        match_time = oldest.match_time
        id = oldest.id

    new_highlight, _ = LatestHighlight.objects.update_or_create(id=id,
                                                            link=highlight.link,
                                                            img_link=highlight.img_link,
                                                            time_since_added=highlight.time_since_added,
                                                            match_time=match_time,
                                                            team1=team1,
                                                            score1=highlight.score1,
                                                            team2=team2,
                                                            score2=highlight.score2,
                                                            category=category,
                                                            view_count=highlight.view_count,
                                                            source=highlight.source,
                                                            sent=sent,
                                                            goal_data=highlight.goal_data,
                                                            type=highlight.type)

    return new_highlight
Exemplo n.º 5
0
def get_highlights_for_team_or_competition(team_or_competition_name):
    highlights = []

    # team
    if has_team(team_or_competition_name):
        team = football_team_manager.get_football_team(team_or_competition_name)

        highlights = LatestHighlight.objects.filter(
            Q(team1=team,
              sent=True,
              valid=True,
              ready=True,
              score1__gte=0,
              score2__gte=0,
              source__in=sources.get_available_sources()) |
            Q(team2=team,
              sent=True,
              valid=True,
              ready=True,
              score1__gte=0,
              score2__gte=0,
              source__in=sources.get_available_sources()))\
            .order_by('-match_time', '-time_since_added')

    # competition
    elif has_competition(team_or_competition_name):
        competition = football_competition_manager.get_football_competition(team_or_competition_name)

        highlights = LatestHighlight.objects.filter(category=competition,
                                                    sent=True,
                                                    valid=True,
                                                    ready=True,
                                                    score1__gte=0,
                                                    score2__gte=0,
                                                    source__in=sources.get_available_sources())\
            .order_by('-match_time', '-time_since_added')

    return list(highlights)
def get_users_for_competition(competition_name):
    competition = football_competition_manager.get_football_competition(competition_name)
    competitions = RegistrationCompetition.objects.filter(competition_name=competition)
    return [competition.user.facebook_id for competition in competitions]
def delete_competition(fb_id, competition_name):
    competition = football_competition_manager.get_football_competition(competition_name)
    RegistrationCompetition.objects.filter(user_id=fb_id, competition_name=competition).delete()
def add_competition(fb_id, competition_name):
    competition = football_competition_manager.get_football_competition(competition_name)
    RegistrationCompetition.objects.update_or_create(user_id=fb_id, competition_name=competition)