#!/usr/bin/env python3 """ Fix the dropped albums list by removing albums that are actually still in the main Top 500 list. """ 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) # Find albums in main list (ranks 1-500) main_albums = {} for album in albums: rank = int(album['Rank']) if rank <= 500: key = (album['Artist'], album['Album']) main_albums[key] = album print(f"๐Ÿ“Š Found {len(main_albums)} albums in main Top 500 list") # Find incorrectly marked as dropped incorrect_drops = [] correct_drops = [] for album in albums: rank = int(album['Rank']) if rank > 500 and album['Status'].startswith('Dropped'): key = (album['Artist'], album['Album']) if key in main_albums: print(f"โŒ INCORRECT: {album['Artist']} - {album['Album']} (marked as dropped but is in main list at rank {main_albums[key]['Rank']})") incorrect_drops.append(album) else: correct_drops.append(album) print(f"\n๐Ÿ” Analysis:") print(f" โŒ Incorrectly marked as dropped: {len(incorrect_drops)}") print(f" โœ… Correctly marked as dropped: {len(correct_drops)}") if incorrect_drops: print(f"\n๐Ÿงน Removing {len(incorrect_drops)} incorrect dropped entries...") # Remove incorrect drops fixed_albums = [] removed_count = 0 for album in albums: rank = int(album['Rank']) if rank > 500 and album['Status'].startswith('Dropped'): key = (album['Artist'], album['Album']) if key not in main_albums: # Keep this dropped album (it's correctly dropped) fixed_albums.append(album) else: # Remove this (it's incorrectly marked as dropped) removed_count += 1 print(f" ๐Ÿ—‘๏ธ Removed: {album['Artist']} - {album['Album']}") else: # Keep all main list albums fixed_albums.append(album) # Renumber the remaining dropped albums 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} incorrect entries") print(f"๐Ÿ“Š Total albums now: {len(fixed_albums)}") print(f" - Main list (1-500): 500 albums") print(f" - Correctly dropped (501+): {len(correct_drops)} albums") else: print(f"\nโœ… No fixes needed - all dropped albums are correct!") if __name__ == "__main__": main()