Skip to main content
The fetch_home_kits command fetches kit data from the FKAPI bulk endpoint, downloads and optimizes images to AVIF format, and caches the data for use by the home page view.

How it works

1

Read kit slugs

Reads kit slugs from a JSON file (static/data/home_kits_slugs.json)
2

Fetch from FKAPI

Calls FKAPI bulk endpoint to retrieve kit data
3

Download images

Downloads kit images and compresses them to AVIF format
4

Cache data

Saves kit data and images to storage for fast homepage loading

Basic usage

python manage.py fetch_home_kits

Storage backends

The command supports both local and remote storage:
  • Local storage: Files saved to MEDIA_ROOT/home_kits/
  • Cloud storage: Files uploaded to S3/R2 via Django’s default_storage

Storage paths

  • Kit data: home_kits/home_kits_data.json
  • Kit images: home_kits/<kit_slug>.avif
  • Club/brand logos: home_kits/logos/<entity>_<slug>.avif

Configuration

The command requires:
  • FKAPI running: See FKAPI Integration
  • Kit slugs file: footycollect/static/data/home_kits_slugs.json

Kit slugs format

{
  "slugs": [
    "manchester-united-1999-2000-home",
    "barcelona-2010-2011-home",
    "real-madrid-2016-2017-home"
  ]
}

Proxy support

For downloading images through a rotating proxy, configure:
ROTATING_PROXY_URL=http://proxy-server:8000
ROTATING_PROXY_USERNAME=user
ROTATING_PROXY_PASSWORD=pass

Example workflow

1

Create slugs file

Create or update footycollect/static/data/home_kits_slugs.json with desired kit slugs
2

Run command

python manage.py fetch_home_kits
3

Verify output

Check that images were downloaded and data file was created:
# Local storage
ls media/home_kits/

# Check data file
cat footycollect/static/data/home_kits_data.json

Output example

Fetching home kits from FKAPI...
Found 3 kit slugs to fetch
Fetching kits in bulk from FKAPI...
Downloading images for 3 kits...
  Downloaded and optimized: manchester-united-1999-2000-home.avif
  Downloaded and optimized: barcelona-2010-2011-home.avif
  Downloaded and optimized: real-madrid-2016-2017-home.avif
Downloading logos...
  Downloaded club logo: manchester-united.avif
  Downloaded brand logo: adidas.avif
Saved kit data to home_kits/home_kits_data.json
Complete! 3 kits cached for homepage.

Image optimization

All images are automatically optimized:
  • Converted to AVIF format for smaller file size
  • Compressed using optimize_image() utility
  • Transparency preserved where applicable
AVIF images are typically 50-70% smaller than JPEG while maintaining quality.

Scheduling

For production, schedule this command to keep homepage kits fresh:
# Crontab - run weekly
0 3 * * 0 cd /var/www/footycollect && venv/bin/python manage.py fetch_home_kits
Or add to Celery Beat:
from django_celery_beat.models import IntervalSchedule, PeriodicTask

schedule, _ = IntervalSchedule.objects.get_or_create(
    every=7,
    period=IntervalSchedule.DAYS,
)

PeriodicTask.objects.create(
    interval=schedule,
    name="Fetch home kits",
    task="core.tasks.fetch_home_kits",
)

Troubleshooting

Verify FKAPI is running:
curl http://$FKA_API_IP/health
Check environment variables:
echo $FKA_API_IP
echo $API_KEY
Ensure the file exists at the correct path:
ls footycollect/static/data/home_kits_slugs.json
Create it if missing with valid kit slugs from Football Kit Archive.
Check network connectivity and proxy configuration. Images are fetched from Football Kit Archive CDN.If using a proxy, verify credentials:
curl -x $ROTATING_PROXY_URL -U $ROTATING_PROXY_USERNAME:$ROTATING_PROXY_PASSWORD https://httpbin.org/ip
For remote storage (S3/R2), verify credentials:
python manage.py shell
from django.core.files.storage import default_storage
default_storage.exists('test.txt')