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), '*****@*****.**', ['*****@*****.**'])
def get_template_context(self, **kwargs): context = {} # The team is specified in the URL by its slug team = ClubTeam.objects.get(slug=kwargs['slug']) context['clubteam'] = team # The season is specified in the URL by its primary key season_id = int(kwargs['season_pk']) season = Season.objects.get(pk=season_id) context['season'] = season is_current_season = Season.is_current_season(season_id) context['is_current_season'] = is_current_season participation = ClubTeamSeasonParticipation.objects.select_related('team').filter(team=team, season_id=season_id).first() if participation.division_tables_url: context['participation'] = participation context['division'] = participation.division # Delete any existing data for this league table DivisionResult.objects.league_table(season=season, division=participation.division).delete() try: context['div_data'] = get_east_leagues_nw_division(participation.division_tables_url, participation.division, season) except Exception as e: print "Failed to parse league table: {}".format(e) return context