All the things

This commit is contained in:
2022-05-26 14:20:13 +02:00
parent ec7cb4ca57
commit e0445f621e
6 changed files with 336 additions and 6 deletions

46
nporadio2/top2000.py Normal file
View File

@@ -0,0 +1,46 @@
from csv import DictReader
from uuid import UUID
class Top200Song:
def __init__(self, songdict) -> None:
try:
self.id = UUID(songdict["id"])
except ValueError:
self.id = None
self.artist = songdict["artist"]
self.title = songdict["title"]
self.position = int(songdict["position"])
def __str__(self) -> str:
return f"{self.position:4d}: {self.artist} - {self.title}"
def __repr__(self) -> str:
return str(self)
def load_top2000(filename="2021.csv") -> dict[UUID, Top200Song]:
songs = {}
with open(filename) as f:
reader = DictReader(f)
for line in reader:
song = Top200Song(line)
if song.id:
songs[song.id] = song
return songs
if __name__ == "__main__":
from csv import DictReader
songs = []
with open("2021.csv") as f:
reader = DictReader(f)
for line in reader:
print(line)
songs.append(Top200Song(line))
for song in songs:
print(song)