Skip to content

Commit

Permalink
feat: add update_teams_for_competitions management command
Browse files Browse the repository at this point in the history
  • Loading branch information
eldersantoss committed Apr 3, 2024
1 parent 25ee09f commit 309b81b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions core/management/commands/update_teams_for_competitions.py
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.")

0 comments on commit 309b81b

Please sign in to comment.