fixed missing images

This commit is contained in:
nvrl committed 2026-02-16 13:25:46 +01:00
1 parent 2a73c062bb
commit 244795e887
31 files changed
+47 -12

No files matched your search

@@ -41,9 +41,13 @@ class Command(BaseCommand):
iced_tea = Category.objects.get_or_create(name='Iced Tea', defaults={'slug': 'iced-tea'})[0]
packs = Category.objects.get_or_create(name='Packs and other', defaults={'slug': 'packs-and-other'})[0]
# Try both common locations for the legacy folder
legacy_dir = os.path.join(settings.BASE_DIR, 'legacy')
if not os.path.exists(legacy_dir):
self.stdout.write(self.style.ERROR(f"Legacy directory not found at {legacy_dir}"))
legacy_dir = os.path.join(settings.BASE_DIR, '..', 'legacy')
if not os.path.exists(legacy_dir):
self.stdout.write(self.style.ERROR(f"Legacy directory not found. Checked: {os.path.join(settings.BASE_DIR, 'legacy')} and {os.path.join(settings.BASE_DIR, '..', 'legacy')}"))
return
json_files = [f for f in os.listdir(legacy_dir) if f.endswith('.json')]
@@ -21,17 +21,15 @@ class Command(BaseCommand):
if not url:
return None
try:
# Simple caching: check if we already have a local image for this URL
# (In a real app, you might compare filenames or hashes)
img_temp = NamedTemporaryFile(delete=True)
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
with urllib.request.urlopen(req) as response:
img_temp.write(response.read())
img_temp.flush()
img_temp.seek(0) # IMPORTANT: go back to start
# Use extension from URL or default to .png
ext = url.split('.')[-1].split('?')[0]
if len(ext) > 4: ext = 'png'
if len(ext) > 4 or len(ext) < 3: ext = 'png'
filename = f"{flavor_name.replace(' ', '_').lower()}.{ext}"
return File(img_temp, name=filename)
except Exception as e: