<reponame>luthfeew/waifu-dataset
import os, requests, json, shutil

finalId = 32796
waifus = []

if os.path.isdir("images") == False:
    os.mkdir("images", 0o755)

for waifuId in range(1, finalId):
    try:
        r = requests.get(
            "https://mywaifulist.moe/api/waifu/" + str(waifuId),
            headers={"x-requested-with": "XMLHttpRequest"},
        )
        if r.text != "":
            waifu = r.json()["data"]
            print(
                "Scrapped " + str(waifu["id"]) + "/" + str(finalId) + " - " + waifu["name"]
            )
            imageURL = requests.get(
                "https://mywaifulist.moe/api/waifu/" + str(waifuId) + "/gallery?page=0",
                headers={"x-requested-with": "XMLHttpRequest"},
            ).json()["data"][0]["path"]
            waifuFile = str(waifuId)
            imageData = requests.get(imageURL, stream=True)
            with open("images/" + waifuFile + ".jpeg", "wb") as f:
                imageData.raw.decode_content = True
                shutil.copyfileobj(imageData.raw, f)
            waifu["display_picture"] = "images/" + waifuFile + ".jpeg"
            waifus.append(waifu)
            open("waifus.json", "w+").write(json.dumps(waifus))
    except:
        pass
import os, requests, json, shutil

finalId = 32796
waifus = []

if os.path.isdir("images") == False:
    os.mkdir("images", 0o755)

for waifuId in range(1, finalId):
    try:
        r = requests.get(
            "https://mywaifulist.moe/api/waifu/" + str(waifuId),
            headers={"x-requested-with": "XMLHttpRequest"},
        )
        if r.text != "":
            waifu = r.json()["data"]
            print(
                "Scrapped " + str(waifu["id"]) + "/" + str(finalId) + " - " + waifu["name"]
            )
            imageURL = requests.get(
                "https://mywaifulist.moe/api/waifu/" + str(waifuId) + "/gallery?page=0",
                headers={"x-requested-with": "XMLHttpRequest"},
            ).json()["data"][0]["path"]
            waifuFile = str(waifuId)
            imageData = requests.get(imageURL, stream=True)
            with open("images/" + waifuFile + ".jpeg", "wb") as f:
                imageData.raw.decode_content = True
                shutil.copyfileobj(imageData.raw, f)
            waifu["display_picture"] = "images/" + waifuFile + ".jpeg"
            waifus.append(waifu)
            open("waifus.json", "w+").write(json.dumps(waifus))
    except:
        pass