Make it work
Browse files- heatmap.py +3 -6
heatmap.py
CHANGED
|
@@ -12,23 +12,20 @@ def fetch_recent_songs(client: Spotify):
|
|
| 12 |
max_iterations = 30
|
| 13 |
it = 0
|
| 14 |
while it < max_iterations and cursor["cursors"] is not None:
|
| 15 |
-
cursor = cursor["cursors"]["before"]
|
| 16 |
recently_played.extend(cursor["items"])
|
| 17 |
|
| 18 |
return recently_played
|
| 19 |
|
| 20 |
def build_heatmap(recent_songs: List[dict]) -> np.ndarray:
|
| 21 |
heatmap = np.zeros((7, 20))
|
| 22 |
-
now = datetime.now()
|
| 23 |
|
| 24 |
for track in recent_songs:
|
| 25 |
played_at = parse(track["played_at"])
|
| 26 |
weekday = datetime.weekday(played_at)
|
| 27 |
week_offset = (now - played_at).days // 7
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
heatmap[weekday, -week_offset]
|
| 31 |
-
|
| 32 |
return heatmap
|
| 33 |
|
| 34 |
|
|
|
|
| 12 |
max_iterations = 30
|
| 13 |
it = 0
|
| 14 |
while it < max_iterations and cursor["cursors"] is not None:
|
| 15 |
+
cursor = client.current_user_recently_played(before=cursor["cursors"]["before"])
|
| 16 |
recently_played.extend(cursor["items"])
|
| 17 |
|
| 18 |
return recently_played
|
| 19 |
|
| 20 |
def build_heatmap(recent_songs: List[dict]) -> np.ndarray:
|
| 21 |
heatmap = np.zeros((7, 20))
|
| 22 |
+
now = datetime.now().astimezone()
|
| 23 |
|
| 24 |
for track in recent_songs:
|
| 25 |
played_at = parse(track["played_at"])
|
| 26 |
weekday = datetime.weekday(played_at)
|
| 27 |
week_offset = (now - played_at).days // 7
|
| 28 |
+
heatmap[weekday, -week_offset] +=1
|
|
|
|
|
|
|
|
|
|
| 29 |
return heatmap
|
| 30 |
|
| 31 |
|