Example #1
0
    def get_template_context(self, **kwargs):
        """ Updates the AccidentalTourist stats for the specified season and then returns
            the context data for the template, containing just a 'goalking_list' item
        """
        # The season_slug keyword arg should always be supplied to this view
        season = Season.objects.get(slug=kwargs['season_slug'])
        GoalKing.update_for_season(season)

        return {'goalking_list': self.get_goalking_list(season)}
Example #2
0
    def handle(self, *args, **options):
        errors = []
        season = Season.current()

        try:
            # Update goal king
            GoalKing.update_for_season(season)
        except Exception as e:
            errors.append("Failed to update Goal-King: {}".format(e))

        try:
            # Update Southerners league
            update_southerners_stats_for_season(season)
        except Exception as e:
            errors.append("Failed to update Southerners League: {}".format(e))

        try:
            # Update opposition stats
            update_all_club_stats()
        except Exception as e:
            errors.append("Failed to update Opposition Club Stats: {}".format(e))

        try:
            # Update ClubTeamSeasonParticipation stats
            update_participation_stats_for_season(season)
        except Exception as e:
            errors.append("Failed to update Club Team Season Participation Stats: {}".format(e))

        # Scrape league tables
        participations = ClubTeamSeasonParticipation.objects.current().select_related('team', 'division')

        for participation in participations:
            try:
                DivisionResult.objects.league_table(season=season, division=participation.division).delete()
                try:
                    league_scraper.get_east_leagues_nw_division(participation.division_tables_url, participation.division, season)
                except Exception as e:
                    print "Failed to parse league table: {}".format(e)
            except Exception as e:
                errors.append("Failed to scrape league table from {}: {}".format(participation.division_tables_url, e))

        try:
            # Delete all training session entries from before yesterday (we don't care about
            # training sessions in the past)
            self.purge_training_sessions()
        except Exception as e:
            errors.append("Failed to purge training sessions: {}".format(e))

        if errors:
            send_mail("Nightly build task failed", "\n".join(errors), '*****@*****.**', ['*****@*****.**'])
Example #3
0
    def handle(self, *args, **options):
        errors = []
        season = Season.current()

        try:
            # Update goal king
            GoalKing.update_for_season(season)
            print('Updated Goal King entries for the current season')
        except Exception as e:
            errors.append("Failed to update Goal-King: {}".format(e))

        try:
            # Update Southerners league
            update_southerners_stats_for_season(season)
            print('Updated Southerners league for the current season')
        except Exception as e:
            errors.append("Failed to update Southerners League: {}".format(e))

        try:
            # Update opposition stats
            update_all_club_stats()
            print('Updated all opposition club stats')
        except Exception as e:
            errors.append(
                "Failed to update Opposition Club Stats: {}".format(e))

        try:
            # Update ClubTeamSeasonParticipation stats
            update_participation_stats_for_season(season)
            print(
                'Updated Club Team Season Participation stats for the current season'
            )
        except Exception as e:
            errors.append(
                "Failed to update Club Team Season Participation Stats: {}".
                format(e))

        try:
            # Delete all training session entries from before yesterday
            # (we don't care about training sessions in the past)
            yesterday = timezone.now() - timedelta(days=1)
            TrainingSession.objects.before(yesterday).delete()
            print("Purged all training sessions from before yesterday")
        except Exception as e:
            errors.append("Failed to purge training sessions: {}".format(e))

        # Scrape league tables
        query = Q(division_tables_url__isnull=True) | Q(division_tables_url='')
        participations = ClubTeamSeasonParticipation.objects.current().exclude(
            query).select_related('team', 'division')

        for participation in participations:
            try:
                league_scraper.get_east_leagues_division(
                    participation.division_tables_url, participation.division,
                    season)
                print('Scraped league table for ' +
                      participation.division_tables_url)
            except Exception as e:
                errors.append(
                    "Failed to scrape league table from {}: {}".format(
                        participation.division_tables_url, e))

        for error in errors:
            print(error)