aboutsummaryrefslogtreecommitdiffstats
path: root/modules/artists.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/artists.py')
-rw-r--r--modules/artists.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/modules/artists.py b/modules/artists.py
new file mode 100644
index 00000000..3612758b
--- /dev/null
+++ b/modules/artists.py
@@ -0,0 +1,25 @@
+import os.path
+import csv
+from collections import namedtuple
+
+Artist = namedtuple("Artist", ['name', 'weight', 'category'])
+
+
+class ArtistsDatabase:
+ def __init__(self, filename):
+ self.cats = set()
+ self.artists = []
+
+ if not os.path.exists(filename):
+ return
+
+ with open(filename, "r", newline='', encoding="utf8") as file:
+ reader = csv.DictReader(file)
+
+ for row in reader:
+ artist = Artist(row["artist"], float(row["score"]), row["category"])
+ self.artists.append(artist)
+ self.cats.add(artist.category)
+
+ def categories(self):
+ return sorted(self.cats)