#!/usr/bin/env python3
import json
import sys
import os
import requests
import time

# Read the message history from stdin (will be provided by shell)
def main():
    # Get all image URLs from the first 100 messages
    image_urls = []
    
    # Manually extracted from the visible message history
    attachments = [
        "https://cdn.discordapp.com/attachments/1475846477589905530/1479441743966503039/Screenshot_2026-03-06_at_11.33.00_AM.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478520384063017013/s8-calf-nursing.png", 
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478519986107580629/s8-calf-nursing.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478518412840931479/Screenshot_2026-03-03_at_10.24.13_PM.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478514983800275077/s4v20-styled.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478514389043777536/science_v3.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478514362376257656/science_v2.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478514336077975735/science_v1.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478510997994995887/chart_repeat_v3.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478510969687904358/chart_ceiling_v3.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478509017226543307/chart_repeat_v2.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478508990081142795/chart_ceiling_v2.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478508114658463844/chart_repeat.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478508084459602083/chart_ceiling.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478514983800275077/s4v20-styled.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478502964078444614/s4v19-fresh.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478501988609167540/s4v18-smaller-cake.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478501779728633957/image.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478501621540454541/s4v17-frontal.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478501357446103090/s4v16-mid.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478500368395800729/s4v15-calm.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478498026657026128/s4v14-hole.png",
        "https://cdn.discordapp.com/attachments/1475846477589905530/1478497493695201342/s4v13-final-b.png"
    ]
    
    os.makedirs("public/visuals-channel-images", exist_ok=True)
    
    for i, url in enumerate(attachments, 1):
        try:
            filename = url.split('/')[-1]
            if '?' in filename:
                filename = filename.split('?')[0]
            
            print(f"Downloading {i}/{len(attachments)}: {filename}")
            
            response = requests.get(url, timeout=30)
            response.raise_for_status()
            
            with open(f"public/visuals-channel-images/{filename}", 'wb') as f:
                f.write(response.content)
                
            time.sleep(0.5)  # Be nice to Discord CDN
            
        except Exception as e:
            print(f"Error downloading {url}: {e}")
            continue
    
    # Create zip
    os.system('cd public && zip -r visuals-channel-complete.zip visuals-channel-images/')
    print(f"\nCreated: public/visuals-channel-complete.zip")
    
    # Check size
    size = os.path.getsize("public/visuals-channel-complete.zip")
    print(f"Size: {size/1024/1024:.1f} MB")

if __name__ == "__main__":
    main()