#!/usr/bin/env python3
"""Fix the powerball CSV file format."""

import shutil

# Read the original file
with open('powerball_numbers.csv', 'r') as f:
    lines = f.readlines()

# Create backup
shutil.copy('powerball_numbers.csv', 'powerball_numbers.csv.backup')

# Open output file
with open('powerball_numbers.csv', 'w') as f:
    # Write header
    f.write('Draw Date,Winning Numbers,Multiplier\n')
    
    # Process each line
    for line in lines:
        parts = line.strip().split(',')
        
        # Extract components
        month = parts[0]
        day_year = parts[1].split('/')
        day = day_year[0]
        year = day_year[1]
        
        # Format date as MM/DD/YYYY
        date = f"{int(month):02d}/{int(day):02d}/{year}"
        
        # Get the 6 winning numbers (5 white balls + 1 powerball)
        numbers = ' '.join(parts[2:8])
        
        # Get the multiplier
        multiplier = parts[8]
        
        # Write the formatted line
        f.write(f'{date},{numbers},{multiplier}\n')

print("✓ File fixed! Created backup at powerball_numbers.csv.backup")
print("\nFirst few lines of fixed file:")
with open('powerball_numbers.csv', 'r') as f:
    for i, line in enumerate(f):
        if i < 5:
            print(line.strip())
        else:
            break
