diff --git a/nba_data/management/commands/delete_advanced_data.py b/nba_data/management/commands/delete_advanced_data.py new file mode 100644 index 0000000..7b15b8f --- /dev/null +++ b/nba_data/management/commands/delete_advanced_data.py @@ -0,0 +1,18 @@ +from django.core.management.base import BaseCommand +from nba_data.models import PlayerAdvancedData +from django.db import connection + +class Command(BaseCommand): + # Provides a description for use with the custom django management command (python manage.py help). + help = 'Delete all player ADVANCED data with season specified and reset primary key sequence in DB' + + def handle(self, *args, **options): + # Delete player data with season + season = 2006 + PlayerAdvancedData.objects.filter(season=season).delete() + + # Reset the PK sequence + with connection.cursor() as cursor: + cursor.execute('ALTER SEQUENCE nba_data_playeradvanceddata_id_seq RESTART WITH 1;') + + self.stdout.write(self.style.SUCCESS('Successfully deleted all players with season = {} in DB'.format(season))) \ No newline at end of file diff --git a/nba_data/nba_scraper_playoffs_advanced.py b/nba_data/nba_scraper_playoffs_advanced.py index 52a8dc7..2b3bb4d 100644 --- a/nba_data/nba_scraper_playoffs_advanced.py +++ b/nba_data/nba_scraper_playoffs_advanced.py @@ -34,7 +34,7 @@ season = input('What season? ') teams2 = 'PHI' -for team in teams2: +for team in teams_data: url_make = 'https://www.basketball-reference.com/teams/' + team + '/' + season + '.html' response = requests.get(url_make)