Created
March 23, 2025 21:06
-
-
Save purarue/67d7da64f97faf2b67c6b0ac37e94b1b to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import requests | |
import time | |
import fileinput | |
def fetch(id: int): | |
time.sleep(1) | |
query = ( | |
"""query($id: Int, $type: MediaType){Media(idMal: $id, type: $type){siteUrl}}""" | |
) | |
variables = {"id": id, "type": "ANIME"} | |
url = "https://graphql.anilist.co" | |
response = requests.post(url, json={"query": query, "variables": variables}) | |
data = response.json().get("data", {}) | |
if not data: | |
return None | |
return data.get("Media", {}).get("siteUrl", "") | |
def main() -> None: | |
# pipe mal ids to STDIN/pass in a file as the first argument to this script | |
# prints anilist URLs if they exist | |
for mal_id in fileinput.input(): | |
line = int(mal_id) | |
resp = fetch(line) | |
print(f"{line} -> {resp}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment