Created
March 22, 2022 13:36
-
-
Save baseplate-admin/69c46baef5ff64b6491361aa2fa9667f to your computer and use it in GitHub Desktop.
Scrape `jikan.moe` for anime info
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 os | |
import time | |
import json | |
import requests | |
ANIME_DIR = os.path.join(os.getcwd(), "animes") | |
ANIME_NO = 3011 | |
while True: | |
res = requests.get(f"https://api.jikan.moe/v4/anime/{ANIME_NO}") | |
data = res.json() | |
if res.status_code == 200 and data.get("status", None) != 404: | |
BASE_DIR = f"{ANIME_DIR}\\{ANIME_NO}" | |
os.makedirs(BASE_DIR) if not os.path.isdir(BASE_DIR) else None | |
file = open(f"{BASE_DIR}/anime.json", "w+") | |
json.dump(data, file, indent=4) | |
file.close() | |
# EPISODE_DONE = 0 | |
# episodes = data["data"]["episodes"] | |
# while episodes >= EPISODE_DONE: | |
# _res = requests.get( | |
# f"https://api.jikan.moe/v4/anime/{ANIME_NO}/episodes/{EPISODE_DONE}" | |
# ) | |
# _data = _res.json() | |
# if _data.get("title", None) != "": | |
# os.makedirs(f"{BASE_DIR}\\episodes") if not os.path.isdir( | |
# f"{BASE_DIR}\\episodes" | |
# ) else None | |
# _file = open(f"{BASE_DIR}/episodes/{EPISODE_DONE}.json", "w+") | |
# json.dump(_data, _file, indent=4) | |
# _file.close() | |
# print(f"Got info for {ANIME_NO} | Episode {EPISODE_DONE}") | |
# else: | |
# print(f"Missed info for {ANIME_NO} | Episode {EPISODE_DONE}") | |
# time.sleep(1) | |
# EPISODE_DONE += 1 | |
print(f"Got Info for {ANIME_NO}") | |
else: | |
print(f"Missed info for {ANIME_NO}") | |
ANIME_NO += 1 | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment