-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add update_teams_for_competitions management command
- Loading branch information
1 parent
25ee09f
commit 309b81b
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from time import sleep | ||
|
||
import requests | ||
from django.conf import settings | ||
from django.core.management.base import BaseCommand, CommandParser | ||
|
||
from core.models import Competition | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Get data from Football API and update teams for the competitions." | ||
|
||
def add_arguments(self, parser: CommandParser) -> None: | ||
parser.add_argument( | ||
"--season", | ||
type=int, | ||
help="Football API league season", | ||
default=None | ||
) | ||
parser.add_argument( | ||
"--league_ids", | ||
type=int, | ||
nargs="+", | ||
help="Football API league ids separeted by space", | ||
default=[] | ||
) | ||
|
||
def handle(self, *args, **options): | ||
season = options["season"] | ||
league_ids = options["league_ids"] | ||
|
||
data_source_ids = [l + season for l in league_ids] | ||
|
||
competitions = Competition.objects.filter(data_source_id__in=data_source_ids) if data_source_ids else Competition.objects.all() | ||
|
||
for competition in competitions: | ||
competition.get_teams() | ||
self.stdout.write(f"Teams updated for {competition.name}") | ||
|
||
self.stdout.write("Teams of competitions updating done.") |