-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport_chadwambles.py
33 lines (27 loc) · 1.07 KB
/
import_chadwambles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import csv
import db
FILENAME = "TheBeatlesCleaned.csv"
def main():
songs = db.load()
with open(FILENAME) as f:
for row in csv.DictReader(f):
# Keys are: id,year,album,song,danceability,energy,speechiness,acousticness,liveness,valence,duration_ms
title = row["song"]
song = db.get_song_by_title(songs, title)
if song is None:
print(f"Can't find song \"{title}\"")
else:
song["chadwambles"] = {
"year": int(row["year"]),
"album": row["album"],
"song": row["song"],
"danceability": float(row["danceability"]),
"energy": float(row["energy"]),
"speechiness": float(row["speechiness"]),
"acousticness": float(row["acousticness"]),
"liveness": float(row["liveness"]),
"valence": float(row["valence"]),
"duration_ms": int(row["duration_ms"]),
}
db.save(songs)
main()