Created
May 6, 2024 15:57
-
-
Save Shiroizu/e93d4f95a1960b2df9ed01af527b118c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import time | |
user_id = | |
page = 1 | |
save_file = f"Rated songs by user {user_id}.txt" | |
all_song_ids = [] | |
while True: | |
params = { | |
"getTotalCount": "true", | |
"maxResults": "50", | |
"groupByRating": "false", | |
"sort": "RatingDate", | |
"start": str(50 * (page - 1)), | |
} | |
r = requests.get(f"https://vocadb.net/api/users/{user_id}/ratedSongs", params) | |
songs_in_total = r.json()["totalCount"] | |
r.raise_for_status() | |
pages_total = (songs_in_total // 50) + 1 | |
songs = r.json()["items"] | |
if not songs: | |
break | |
song_ids = [str(song["song"]["id"]) for song in songs] | |
all_song_ids.extend(song_ids) | |
print(f"Page {page}/{pages_total}:") | |
print(",".join(song_ids)) | |
page += 1 | |
time.sleep(1) | |
with open(save_file, "w") as f: | |
f.write("\n".join(all_song_ids)) | |
print(f"\nSaved {len(all_song_ids)} song ids to {save_file}.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment