#!/usr/bin/env python3 """ Update the CSV to mark only the correct 8 albums as "New in 2023". """ import csv def main(): # The correct 8 new albums correct_new_albums = { 491: ('Harry Styles', "Harry's House"), 466: ('Black Uhuru', 'Red'), 437: ('Gorillaz', 'Demon Days'), 430: ('Bad Bunny', 'Un Verano Sin Ti'), 358: ('Olivia Rodrigo', 'Sour'), 351: ('SZA', 'SOS'), 170: ('Taylor Swift', 'Folklore'), 71: ('Beyonce', 'Renaissance') } print(f"✅ Correcting to mark only {len(correct_new_albums)} albums as 'New in 2023'") # Read current data 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) # Update statuses updated_count = 0 for album in albums: rank = int(album['Rank']) # If this rank should be marked as "New in 2023" if rank in correct_new_albums: expected_artist, expected_album = correct_new_albums[rank] # Verify it matches if album['Artist'] == expected_artist or expected_album.lower() in album['Album'].lower(): album['Status'] = 'New in 2023' updated_count += 1 print(f"✅ #{rank} - {album['Artist']} - {album['Album']} -> New in 2023") else: print(f"⚠️ Rank {rank} mismatch: expected {expected_artist} - {expected_album}, got {album['Artist']} - {album['Album']}") # If it's currently marked as "New in 2023" but not in our list, change it elif 'New in 2023' in album.get('Status', ''): album['Status'] = 'No change' print(f"❌ #{rank} - {album['Artist']} - {album['Album']} -> Changed to No change") # Write updated 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(albums) print(f"\n✅ Updated CSV with {updated_count} albums marked as 'New in 2023'") print(f"📁 Saved to: top_500_albums_2023.csv") if __name__ == "__main__": main()