Last active
April 30, 2020 01:15
-
-
Save purarue/c3aba00ff41116ba396c1e96b4b62c9e to your computer and use it in GitHub Desktop.
download a users list from MAL
This file contains hidden or 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 sys | |
import time | |
import requests | |
def download_list(username: str): | |
base_url = "https://myanimelist.net/animelist/{username}/load.json?offset={offset}&status=7" | |
offset = 0 | |
entries = [] | |
while True: | |
url = base_url.format(username=username, offset=offset) | |
print("Requesting '{}'...".format(url)) | |
resp = requests.get(url) | |
if resp.status_code == 400: | |
print("Could not get list for user {}".format(username), file=sys.stderr) | |
print(resp.status_code, resp.text, file=sys.stderr) | |
sys.exit(1) | |
resp_json = resp.json() | |
# if the next offset didnt return any entries, we've downloaded the users list | |
if len(resp_json) == 0: | |
break | |
for anime in resp_json: | |
entries.append(anime) | |
time.sleep(3) | |
offset += 300 | |
return entries | |
if __name__ == "__main__": | |
print(download_list("lanblade")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment