Skip to content

Commit

Permalink
fix_rate_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
retrohacking committed Oct 9, 2023
1 parent d1466c4 commit f53f46c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import spotipy
from time import localtime
from time import localtime, sleep
REDIRECT="http://localhost:1337"
SCOPE="playlist-modify-private playlist-modify-public playlist-read-private playlist-read-collaborative"
TOKENS_FILE="tokens.json"
Expand All @@ -9,6 +9,7 @@
YEAR=localtime()[0]
GITHUB="https://github.com/retrohacking"

RATE_LIMIT=100
LIMIT_PLAYLIST_TRACK=100
DEFAULT_GENRES=["rock", "metal", "funk", "punk", "trap", "hip hop", "rap", "pop", "r&b", "reggae", "soul"]
PLAYLISTS_PREFIX="GENSORT_"
Expand Down
6 changes: 6 additions & 0 deletions utils/gensort_functionalities.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def collect_tracks(spotify,playlist):
artist=spotify.artist(sp_track["artists"][0]["id"])
tracks[track["track"]["id"]]=artist["genres"]
print(f'\rLoading{"."*((i%3)+1)}{" "*(3-(i%3)+1)}', end='')
if (i%RATE_LIMIT==0):
sleep(3.0)
i+=1
return tracks

Expand Down Expand Up @@ -87,12 +89,16 @@ def gensort_playlists(chosen, playlists, user_playlists, spotify):
for song in playlists[sorted_playlists_name]:
spotify.playlist_add_items(final_playlist_id, [song])
print(f'\rLoading{"."*((i%3)+1)}{" "*(3-(i%3)+1)}', end='')
if (i%RATE_LIMIT==0):
sleep(3.0)
i+=1
else:
new_playlist_id=spotify.user_playlist_create(username, final_playlist_name, public=False, collaborative=False, description=PLAYLISTS_DESCRIPTION)["id"]
i=0
for song in playlists[sorted_playlists_name]:
spotify.playlist_add_items(new_playlist_id, [song])
print(f'\rLoading{"."*((i%3)+1)}{" "*(3-(i%3)+1)}', end='')
if (i%RATE_LIMIT==0):
sleep(3.0)
i+=1
print(f"\r{len(playlists[sorted_playlists_name])} songs have been added to {final_playlist_name}")

0 comments on commit f53f46c

Please sign in to comment.