#!/usr/bin/env python3 """ Fix the White Album duplication - it's listed both in main list and dropped. """ import csv def main(): # Read current CSV albums = [] with open('top_500_albums_2023.csv', 'r', encoding='utf-8') as file: reader = csv.DictReader(file) for row in reader: albums.append(row) print("šŸ” Looking for White Album duplication...") # Find White Album entries white_album_entries = [] for album in albums: if album['Artist'] == 'The Beatles' and ('White Album' in album['Album'] or album['Album'] == 'The Beatles'): white_album_entries.append(album) print(f" Found: Rank {album['Rank']} - {album['Artist']} - {album['Album']} ({album['Status']})") if len(white_album_entries) > 1: print(f"\nāŒ Found {len(white_album_entries)} White Album entries - removing duplicate") # Remove the dropped version (should be rank 502) fixed_albums = [] removed_count = 0 for album in albums: # Remove the dropped White Album entry if (album['Artist'] == 'The Beatles' and 'White Album' in album['Album'] and album['Status'].startswith('Dropped')): print(f" šŸ—‘ļø Removed duplicate: Rank {album['Rank']} - {album['Album']}") removed_count += 1 else: fixed_albums.append(album) # Renumber the remaining albums after rank 500 current_rank = 501 for album in fixed_albums: if int(album['Rank']) > 500: album['Rank'] = str(current_rank) current_rank += 1 # Write corrected CSV with open('top_500_albums_2023.csv', 'w', newline='', encoding='utf-8') as file: fieldnames = ['Rank', 'Artist', 'Album', 'Status', 'Info', 'Description'] writer = csv.DictWriter(file, fieldnames=fieldnames) writer.writeheader() writer.writerows(fixed_albums) print(f"\nāœ… Fixed! Removed {removed_count} duplicate entry") print(f"šŸ“Š Total albums now: {len(fixed_albums)}") else: print("āœ… No duplicates found") if __name__ == "__main__": main()