Skip to content

Anime Classes

pymoe.anime

setMalClient(client_id)

This is a helper function to set the MyAnimeList Client ID at both endpoints.

PARAMETER DESCRIPTION
client_id

Your Client ID

TYPE: str

Source code in pymoe\anime\__init__.py
def setMalClient(client_id: str):
    """
    This is a helper function to set the MyAnimeList Client ID at both endpoints.

    :param client_id: Your Client ID
    """
    mg.settings["header"]["X-MAL-CLIENT-ID"] = client_id
    ms.settings["header"]["X-MAL-CLIENT-ID"] = client_id

pymoe.anime.get

character(item_id)

Return a Character from Anilist with the given ID

Source code in pymoe\anime\get\__init__.py
def character(item_id: int):
    """
    Return a Character from Anilist with the given ID
    """
    return anilist.character(item_id)

episode(item_id)

Return an Episode from Anilist with the given ID

Source code in pymoe\anime\get\__init__.py
def episode(item_id: int):
    """
    Return an Episode from Anilist with the given ID
    """
    return anilist.episode(item_id)

show(item_id)

Return a Show from Anilist with the given ID

Source code in pymoe\anime\get\__init__.py
def show(item_id: int):
    """
    Return a Show from Anilist with the given ID
    """
    return anilist.show(item_id)

staff(item_id)

Return a Staff member from Anilist with the given ID

Source code in pymoe\anime\get\__init__.py
def staff(item_id: int):
    """
    Return a Staff member from Anilist with the given ID
    """
    return anilist.staff(item_id)

studio(item_id)

Return a Studio from Anilist with the given ID

Source code in pymoe\anime\get\__init__.py
def studio(item_id: int):
    """
    Return a Studio from Anilist with the given ID
    """
    return anilist.studio(item_id)

pymoe.anime.get.anilist

settings = {'header': {'Content-Type': 'application/json', 'User-Agent': 'Pymoe (github.com/ccubed/PyMoe)', 'Accept': 'application/json'}, 'apiurl': 'https://graphql.anilist.co'} module-attribute

character(item_id)

Get a character with a certain ID in the anilist API.

PARAMETER DESCRIPTION
item_id

The ID of the character you want information on.

TYPE: int

Source code in pymoe\anime\get\anilist.py
def character(item_id: int):
    """
    Get a character with a certain ID in the anilist API.

    :param item_id: The ID of the character you want information on.
    """
    query_string = """
        query ($id: Int){
            Character (id: $id){
                name{
                    full
                }
                image {
                    large
                    medium
                }
                description
                gender
                age
                siteUrl
                media{
                    nodes{
                        id
                        idMal
                        title {
                            romaji
                            english
                            native
                        }
                        coverImage {
                            extraLarge
                            large
                            medium
                            color
                        }
                        siteUrl
                    }
                }
            }
        }
    """

    r = requests.post(
        settings["apiurl"],
        headers=settings["header"],
        json={"query": query_string, "variables": {"id": item_id}},
    )

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if "errors" in jsd:
            raise serverError(r.text, r.status_code)
        else:
            return jsd

episode(item_id)

Unsupported on Anilist

Source code in pymoe\anime\get\anilist.py
def episode(item_id: int):
    """
    Unsupported on Anilist
    """
    raise methodNotSupported("pymoe.anime.get.anilist.episode", "anilist")

season(theSeason=None, year=date.today().year, page=1, perPage=3)

Get a list of seasonal anime given a season and year.

PARAMETER DESCRIPTION
theSeason

What Season? See pymoe.utils.helpers for a list of seasons. If not provided we will determine the season for you based on the current month.

TYPE: str DEFAULT: None

year

What year do you want info on?

TYPE: int DEFAULT: year

page

Which page of results do you want?

TYPE: int DEFAULT: 1

perPage

How many results per page?

TYPE: int DEFAULT: 3

Source code in pymoe\anime\get\anilist.py
def season(
    theSeason: str = None, year: int = date.today().year, page: int = 1, perPage: int = 3
):
    """
    Get a list of seasonal anime given a season and year.

    :param theSeason: What Season? See pymoe.utils.helpers for a list of seasons. If not provided we will determine the season for you based on the current month.
    :param year: What year do you want info on?
    :param page: Which page of results do you want?
    :param perPage: How many results per page?
    """
    myseason = theSeason if theSeason else whatSeason(date.today().month)

    query_string = """
        query($season: MediaSeason, $seasonYear: Int, $page: Int, $perPage: Int){
            Page (page: $page, perPage: $perPage) {
                pageInfo {
                    currentPage
                    hasNextPage
                }
                media (season: $season, seasonYear: $seasonYear){
                    id
                    idMal
                    title {
                        romaji
                        english
                        native
                    }
                    description
                    genres
                    coverImage {
                        extraLarge
                        large
                        medium
                        color
                    }
                    isAdult
                    nextAiringEpisode {
                        timeUntilAiring
                        airingAt
                    }
                    startDate {
                        year
                        month
                        day
                    }
                    streamingEpisodes {
                        title
                        thumbnail
                        url
                        site
                    }
                    siteUrl
                    externalLinks {
                        url
                        site
                        language
                    }
                }
            }
        }
    """

    jsonData = {
        "query": query_string,
        "variables": {
            "season": myseason.upper(),
            "seasonYear": year,
            "page": page,
            "perPage": perPage,
        },
    }

    r = requests.post(settings["apiurl"], headers=settings["header"], json=jsonData)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if "errors" in jsd:
            raise serverError(r.text, r.status_code)
        else:
            if jsd["data"]["Page"]["pageInfo"]["hasNextPage"]:
                return anilistWrapper(
                    jsd["data"]["Page"]["media"],
                    jsonData,
                    settings["header"],
                    settings["apiurl"],
                )
            else:
                return jsd["data"]["Page"]["media"]

show(item_id)

Get a show with a certain ID in the anilist API.

PARAMETER DESCRIPTION
item_id

The ID of the show you want information on.

TYPE: int

Source code in pymoe\anime\get\anilist.py
def show(item_id: int):
    """
    Get a show with a certain ID in the anilist API.

    :param item_id: The ID of the show you want information on.
    """
    query_string = """
        query ($id: Int) {
            Media (id: $id, type: ANIME) {
                title {
                    romaji
                    english
                    native
                }
                startDate {
                    year
                    month
                    day
                }
                endDate {
                    year
                    month
                    day
                }
                coverImage {
                    extraLarge
                    large
                    medium
                    color
                }
                bannerImage
                format
                status
                episodes
                season
                seasonYear
                description
                averageScore
                meanScore
                genres
                synonyms
                isAdult
                siteUrl
                idMal
                popularity
                nextAiringEpisode {
                    timeUntilAiring
                    airingAt
                }
                streamingEpisodes {
                    title
                    thumbnail
                    url
                    site
                }
                externalLinks{
                    url
                    site
                    language
                }
                characters {
                    nodes {
                        id
                        name {
                            first
                            last
                        }
                        image {
                            large
                            medium
                        }
                        description
                        gender
                        age
                        siteUrl
                    }
                }
            }
        }
    """

    r = requests.post(
        settings["apiurl"],
        headers=settings["header"],
        json={"query": query_string, "variables": {"id": item_id}},
    )

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if "errors" in jsd:
            raise serverError(r.text, r.status_code)
        else:
            return jsd

staff(item_id)

Get information on a specific staffer given their ID.

PARAMETER DESCRIPTION
item_id

The ID of the staff member you want information on.

TYPE: int

Source code in pymoe\anime\get\anilist.py
def staff(item_id: int):
    """
    Get information on a specific staffer given their ID.

    :param item_id: The ID of the staff member you want information on.
    """
    query_string = """
        query ($id: Int){
            Staff (id: $id){
                name {
                    full
                }
                languageV2
                image {
                    large
                    medium
                }
                description
                primaryOccupations
                gender
                dateOfBirth {
                    year
                    month
                    day
                }
                dateOfDeath {
                    year
                    month
                    day
                }
                age
                homeTown
                yearsActive
                siteUrl
                staffMedia{
                    nodes {
                        id
                        idMal
                        title {
                            romaji
                            english
                            native
                        }
                        coverImage {
                            extraLarge
                            large
                            medium
                            color
                        }
                        siteUrl
                    }
                }
                characters{
                    nodes {
                        name {
                            full
                        }
                        image {
                            large
                            medium
                        }
                        age
                        siteUrl
                        media {
                            nodes {
                                id
                                idMal
                                title {
                                    romaji
                                    english
                                    native
                                }
                                coverImage {
                                    extraLarge
                                    large
                                    medium
                                    color
                                }
                                siteUrl
                            }
                        }
                    }
                }
            }
        }
    """

    r = requests.post(
        settings["apiurl"],
        headers=settings["header"],
        json={"query": query_string, "variables": {"id": item_id}},
    )

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if "errors" in jsd:
            raise serverError(r.text, r.status_code)
        else:
            return jsd

streaming(item_id, page=1, perPage=3)

Given a show ID, return all streaming links for that show. Unlike Kitsu, this returns one streaming link per episode per service.

PARAMETER DESCRIPTION
item_id

The ID of the show you want streaming links for

TYPE: int

Source code in pymoe\anime\get\anilist.py
def streaming(item_id: int, page: int = 1, perPage: int = 3):
    """
    Given a show ID, return all streaming links for that show.
    Unlike Kitsu, this returns one streaming link per episode per service.

    :param item_id: The ID of the show you want streaming links for
    """
    query_string = """
        query ($id: Int) {
            Media(id: $id){
                streamingEpisodes {
                    title
                    thumbnail
                    url
                    site
                }
            }
        }
    """

    r = requests.post(
        settings["apiurl"],
        headers=settings["header"],
        json={"query": query_string, "variables": {"id": item_id}},
    )

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if "errors" in jsd:
            raise serverError(r.text, r.status_code)
        else:
            return jsd

studio(item_id)

Get a studio with a specific id.

PARAMETER DESCRIPTION
item_id

The ID of the studio you want information on.

TYPE: int

Source code in pymoe\anime\get\anilist.py
def studio(item_id: int):
    """
    Get a studio with a specific id.

    :param item_id: The ID of the studio you want information on.
    """
    query_string = """
        query ($id: Int) {
            Studio (id: $id) {
                name
                siteUrl
                media {
                    nodes {
                        id
                        idMal
                        title {
                            romaji
                            english
                            native
                        }
                        coverImage {
                            extraLarge
                            large
                            medium
                            color
                        }
                        siteUrl
                    }
                }
            }
        }
    """

    r = requests.post(
        settings["apiurl"],
        headers=settings["header"],
        json={"query": query_string, "variables": {"id": item_id}},
    )

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if "errors" in jsd:
            raise serverError(r.text, r.status_code)
        else:
            return jsd

pymoe.anime.get.kitsu

settings = {'header': {'Content-Type': 'application/vnd.api+json', 'User-Agent': 'Pymoe (github.com/ccubed/PyMoe)', 'Accept': 'application/vnd.api+json'}, 'apiurl': 'https://kitsu.io/api/edge'} module-attribute

character(item_id)

Get a character with the specific ID from the kitsu api.

PARAMETER DESCRIPTION
item_id

ID of the character you want info on.

TYPE: int

Source code in pymoe\anime\get\kitsu.py
def character(item_id: int):
    """
    Get a character with the specific ID from the kitsu api.

    :param item_id: ID of the character you want info on.
    """
    r = requests.get(
        settings["apiurl"] + "/characters/{}".format(item_id), headers=settings["header"]
    )

    if r.status_code != 200:
        raise serverError(r.text, r.status_code)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        return jsd

episode(item_id)

Get an episode with the specific ID from the kitsu api.

PARAMETER DESCRIPTION
item_id

ID of the episode you want info on.

TYPE: int

Source code in pymoe\anime\get\kitsu.py
def episode(item_id: int):
    """
    Get an episode with the specific ID from the kitsu api.

    :param item_id: ID of the episode you want info on.
    """
    r = requests.get(
        settings["apiurl"] + "/episodes/{}".format(item_id), headers=settings["header"]
    )

    if r.status_code != 200:
        raise serverError(r.text, r.status_code)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        return jsd

show(item_id)

Get a show with the specific ID from the kitsu api.

PARAMETER DESCRIPTION
item_id

ID of the show you want info on.

TYPE: int

Source code in pymoe\anime\get\kitsu.py
def show(item_id: int):
    """
    Get a show with the specific ID from the kitsu api.

    :param item_id: ID of the show you want info on.
    """
    r = requests.get(
        settings["apiurl"] + "/anime/{}".format(item_id), headers=settings["header"]
    )

    if r.status_code != 200:
        raise serverError(r.text, r.status_code)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        return jsd

staff(item_id)

Get a staffer with the specific ID from the kitsu api.

PARAMETER DESCRIPTION
item_id

ID of the staffer you want info on.

TYPE: int

Source code in pymoe\anime\get\kitsu.py
def staff(item_id: int):
    """
    Get a staffer with the specific ID from the kitsu api.

    :param item_id: ID of the staffer you want info on.
    """
    r = requests.get(
        settings["apiurl"] + "/anime-staff/{}/person".format(item_id),
        headers=settings["header"],
    )

    if r.status_code != 200:
        raise serverError(r.text, r.status_code)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        return jsd

studio(item_id)

Get a studio with the specific ID from the kitsu api.

PARAMETER DESCRIPTION
item_id

ID of the studio you want info on.

TYPE: int

Source code in pymoe\anime\get\kitsu.py
def studio(item_id: int):
    """
    Get a studio with the specific ID from the kitsu api.

    :param item_id: ID of the studio you want info on.
    """
    r = requests.get(
        settings["apiurl"] + "/anime-productions/{}/producer".format(item_id),
        headers=settings["header"],
    )

    if r.status_code != 200:
        raise serverError(r.text, r.status_code)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        return jsd

pymoe.anime.get.mal

settings = {'header': {'Content-Type': 'application/json', 'User-Agent': 'Pymoe (github.com/ccubed/PyMoe)', 'Accept': 'application/json', 'X-MAL-CLIENT-ID': None}, 'apiurl': 'https://api.myanimelist.net/v2/', 'default_fields': 'id,title,main_picture,alternative_titles,start_date,end_date,synopsis,mean,rank,nsfw,genres,media_type,status,num_episodes,start_season,broadcast,source,rating,studios,related_anime,related_manga'} module-attribute

character(item_id)

No endpoint exists for this at this time Method not supported

Source code in pymoe\anime\get\mal.py
def character(item_id: int):
    """
    No endpoint exists for this at this time
    Method not supported
    """
    raise methodNotSupported("pymoe.anime.get.mal.character", "myanimelist")

episode(item_id)

No endpoint exists for this at this time Method not supported

Source code in pymoe\anime\get\mal.py
def episode(item_id: int):
    """
    No endpoint exists for this at this time
    Method not supported
    """
    raise methodNotSupported("pymoe.anime.get.mal.episode", "myanimelist")

keyAssert()

This is just an assert. It cancels the request if the API Key is not present.

Source code in pymoe\anime\get\mal.py
def keyAssert():
    """
    This is just an assert. It cancels the request if the API Key is not present.
    """
    if (
        not settings["header"]["X-MAL-CLIENT-ID"]
        or type(settings["header"]["X-MAL-CLIENT-ID"]) != str
    ):
        raise ValueError("pymoe.anime.get.mal.keyAssert: API Key should be a string.")
    else:
        pass

show(item_id, fields=None)

Get a show with the specific ID from the myanimelist api.

PARAMETER DESCRIPTION
item_id

ID of the show you want info on.

TYPE: int

Source code in pymoe\anime\get\mal.py
def show(item_id: int, fields: str = None):
    """
    Get a show with the specific ID from the myanimelist api.

    :param item_id: ID of the show you want info on.
    """
    keyAssert()

    r = requests.get(
        settings["apiurl"] + "anime/{}".format(item_id),
        params={"fields": fields or settings["default_fields"], "nsfw": "true"},
        headers=settings["header"],
    )

    if r.status_code != 200:
        raise serverError(r.text, r.status_code)

    return ujson.loads(r.text)

staff(item_id)

No endpoint exists for this at this time Method not supported

Source code in pymoe\anime\get\mal.py
def staff(item_id: int):
    """
    No endpoint exists for this at this time
    Method not supported
    """
    raise methodNotSupported("pymoe.anime.get.mal.staff", "myanimelist")

streaming(item_id)

No endpoint exists for this at this time Method not supported

Source code in pymoe\anime\get\mal.py
def streaming(item_id: int):
    """
    No endpoint exists for this at this time
    Method not supported
    """
    raise methodNotSupported("pymoe.anime.get.mal.streaming", "myanimelist")

studio(item_id)

No endpoint exists for this at this time Method not supported

Source code in pymoe\anime\get\mal.py
def studio(item_id: int):
    """
    No endpoint exists for this at this time
    Method not supported
    """
    raise methodNotSupported("pymoe.anime.get.mal.studio", "myanimelist")

pymoe.anime.search

characters(term)

Search for characters that match term on anilist

Source code in pymoe\anime\search\__init__.py
def characters(term: str):
    """
    Search for characters that match term on anilist
    """
    return anilist.characters(term)

season(season=None, seasonYear=date.today().year)

Given a season and seasonYear, return the list of seasonal anime from Anilist.

Source code in pymoe\anime\search\__init__.py
def season(season: str = None, seasonYear: int = date.today().year):
    """
    Given a season and seasonYear, return the list of seasonal anime from Anilist.
    """
    return asg(season, seasonYear)

shows(term)

Search for characters that match term on anilist

Source code in pymoe\anime\search\__init__.py
def shows(term: str):
    """
    Search for characters that match term on anilist
    """
    return anilist.shows(term)

staff(term)

Search for characters that match term on anilist

Source code in pymoe\anime\search\__init__.py
def staff(term: str):
    """
    Search for characters that match term on anilist
    """
    return anilist.staff(term)

studios(term)

Search for characters that match term on anilist

Source code in pymoe\anime\search\__init__.py
def studios(term: str):
    """
    Search for characters that match term on anilist
    """
    return anilist.studios(term)

pymoe.anime.search.anilist

settings = {'header': {'Content-Type': 'application/json', 'User-Agent': 'Pymoe (github.com/ccubed/PyMoe)', 'Accept': 'application/json'}, 'apiurl': 'https://graphql.anilist.co'} module-attribute

airingSchedule(item_id)

Given an anime id, return the airing schedule. This returns a full airing schedule, including already aired episodes. If an episode has already aired timeUntilAiring will be <= 0. timeUntilAiring is just seconds.

PARAMETER DESCRIPTION
item_id

The ID of the show you want a schedule for

TYPE: int

Source code in pymoe\anime\search\anilist.py
def airingSchedule(item_id: int):
    """
    Given an anime id, return the airing schedule.
    This returns a full airing schedule, including already aired episodes.
    If an episode has already aired timeUntilAiring will be <= 0.
    timeUntilAiring is just seconds.

    :param item_id: The ID of the show you want a schedule for
    """
    query_string = """\
        query( $id: Int, $page: Int, $perPage: Int ) {
            Page ( page: $page, perPage: $perPage ) {
                pageInfo {
                    currentPage
                    hasNextPage
                }
                airingSchedules ( mediaId: $id ) {
                    id
                    episode
                    timeUntilAiring
                }
            }
        }
    """

    json_params = {
        "query": query_string,
        "variables": {"id": item_id, "page": 1, "perPage": 3},
    }

    r = requests.post(settings["apiurl"], headers=settings["header"], json=json_params)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if "errors" in jsd:
            raise serverError(r.text, r.status_code)
        else:
            if jsd["data"]["Page"]["pageInfo"]["hasNextPage"]:
                return anilistWrapper(
                    jsd["data"]["Page"]["airingSchedules"],
                    json_params,
                    settings["header"],
                    settings["apiurl"],
                )
            else:
                return jsd["data"]["Page"]["airingSchedules"]

characters(term, page=1, perPage=3)

Search for characters that match the term in the API.

PARAMETER DESCRIPTION
term

Search Term

TYPE: str

page

Which page of the results?

TYPE: int DEFAULT: 1

perPage

How many results per page?

TYPE: int DEFAULT: 3

Source code in pymoe\anime\search\anilist.py
def characters(term: str, page: int = 1, perPage: int = 3):
    """
    Search for characters that match the term in the API.

    :param term: Search Term
    :param page: Which page of the results?
    :param perPage: How many results per page?
    """
    query_string = """\
        query ($query: String, $page: Int, $perPage: Int){
            Page (page: $page, perPage: $perPage) {
                pageInfo {
                    currentPage
                    hasNextPage
                }
                characters (search: $query) {
                    id
                    name{
                        first
                        last
                    }
                    image{
                        large
                    }
                    description
                    gender
                    age
                    siteUrl
                    media {
                        nodes {
                            id
                            idMal
                            title {
                                romaji
                                english
                                native
                            }
                            coverImage {
                                extraLarge
                                large
                                medium
                                color
                            }
                            siteUrl
                        }
                    }
                }
            }
        }
    """

    json_params = {
        "query": query_string,
        "variables": {"query": term, "page": page, "perPage": perPage},
    }

    r = requests.post(settings["apiurl"], headers=settings["header"], json=json_params)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if "errors" in jsd:
            raise serverError(r.text, r.status_code)
        else:
            if jsd["data"]["Page"]["pageInfo"]["hasNextPage"]:
                return anilistWrapper(
                    jsd["data"]["Page"]["characters"],
                    json_params,
                    settings["header"],
                    settings["apiurl"],
                )
            else:
                return jsd["data"]["Page"]["characters"]

dynamicRequest(params)

This allows you to run a query you wrote yourself against the anilist API. You have to pass both a properly formatted query and the dictionary of parameters needed. If your request returns multiple results, you will get back a wrapper.

PARAMETER DESCRIPTION
params

Dictionary of parameters needed for the request. Note this needs to include the GraphQL query.

TYPE: Dict

Source code in pymoe\anime\search\anilist.py
def dynamicRequest(params: Dict):
    """
    This allows you to run a query you wrote yourself against the anilist API.
    You have to pass both a properly formatted query and the dictionary of parameters needed.
    If your request returns multiple results, you will get back a wrapper.

    :param params: Dictionary of parameters needed for the request. Note this needs to include the GraphQL query.
    """
    r = requests.post(settings["apiurl"], headers=settings["header"], json=params)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if "errors" in jsd:
            raise serverError(r.text, r.status_code)
        else:
            if jsd["data"]["Page"]["pageInfo"]["hasNextPage"]:
                return anilistWrapper(
                    jsd["data"]["Page"]["airingSchedules"],
                    params,
                    settings["header"],
                    settings["apiurl"],
                )
            else:
                return jsd["data"]["Page"]["airingSchedules"]

shows(term, page=1, perPage=3)

Search for shows(anime) that match the term in the API.

PARAMETER DESCRIPTION
term

Search Term

TYPE: str

page

Which page of the results?

TYPE: int DEFAULT: 1

perPage

How many results per page?

TYPE: int DEFAULT: 3

Source code in pymoe\anime\search\anilist.py
def shows(term: str, page: int = 1, perPage: int = 3):
    """
    Search for shows(anime) that match the term in the API.

    :param term: Search Term
    :param page: Which page of the results?
    :param perPage: How many results per page?
    """
    query_string = """\
        query ($query: String, $page: Int, $perPage: Int){
            Page (page: $page, perPage: $perPage){
                pageInfo {
                    currentPage
                    hasNextPage
                }
                media (search: $query, type: ANIME) {
                    id
                    idMal
                    title {
                        romaji
                        english
                        native
                    }
                    coverImage {
                        extraLarge
                        large
                        medium
                        color
                    }
                    averageScore
                    popularity
                    episodes
                    season
                    hashtag
                    isAdult
                    siteUrl
                    characters {
                        nodes {
                            id
                            name {
                                first
                                last
                            }
                            image {
                                large
                                medium
                            }
                            description
                            gender
                            age
                            siteUrl
                        }
                    }
                }
            }
        }
    """

    json_params = {
        "query": query_string,
        "variables": {"query": term, "page": page, "perPage": perPage},
    }

    r = requests.post(settings["apiurl"], headers=settings["header"], json=json_params)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if "errors" in jsd:
            raise serverError(r.text, r.status_code)
        else:
            if jsd["data"]["Page"]["pageInfo"]["hasNextPage"]:
                return anilistWrapper(
                    jsd["data"]["Page"]["media"],
                    json_params,
                    settings["header"],
                    settings["apiurl"],
                )
            else:
                return jsd["data"]["Page"]["media"]

staff(term, page=1, perPage=3)

Search for staffers that match the term in the API.

PARAMETER DESCRIPTION
term

Search Term

TYPE: str

page

Which page of the results?

TYPE: int DEFAULT: 1

perPage

How many results per page?

TYPE: int DEFAULT: 3

Source code in pymoe\anime\search\anilist.py
def staff(term: str, page: int = 1, perPage: int = 3):
    """
    Search for staffers that match the term in the API.

    :param term: Search Term
    :param page: Which page of the results?
    :param perPage: How many results per page?
    """
    query_string = """\
        query($query: String, $page: Int, $perPage: Int){
            Page(page: $page, perPage: $perPage){
                pageInfo{
                    currentPage
                    hasNextPage
                }
                staff (search: $query){
                    id
                    name {
                        first
                        last
                    }
                    languageV2
                    image {
                        large
                        medium
                    }
                    description
                    primaryOccupations
                    gender
                    dateOfBirth {
                        year
                        month
                        day
                    }
                    dateOfDeath {
                        year
                        month
                        day
                    }
                    age
                    homeTown
                    yearsActive
                    siteUrl
                    staffMedia {
                        nodes {
                            id
                            idMal
                            title {
                                romaji
                                english
                                native
                            }
                            coverImage {
                                extraLarge
                                large
                                medium
                                color
                            }
                            siteUrl
                        }
                    }
                    characters {
                        nodes {
                            name {
                                first
                                last
                            }
                            image {
                                large
                                medium
                            }
                            age
                            siteUrl
                            media {
                                nodes {
                                    id
                                    idMal
                                    title {
                                        romaji
                                        english
                                        native
                                    }
                                    coverImage {
                                        extraLarge
                                        large
                                        medium
                                        color
                                    }
                                    siteUrl
                                }
                            }
                        }
                    }
                }
            }
        }
    """

    json_params = {
        "query": query_string,
        "variables": {"query": term, "page": page, "perPage": perPage},
    }

    r = requests.post(settings["apiurl"], headers=settings["header"], json=json_params)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if "errors" in jsd:
            raise serverError(r.text, r.status_code)
        else:
            if jsd["data"]["Page"]["pageInfo"]["hasNextPage"]:
                return anilistWrapper(
                    jsd["data"]["Page"]["staff"],
                    json_params,
                    settings["header"],
                    settings["apiurl"],
                )
            else:
                return jsd["data"]["Page"]["staff"]

studios(term, page=1, perPage=3)

Search for studios that match the term in the API.

PARAMETER DESCRIPTION
term

Search Term

TYPE: str

page

Which page of the results?

TYPE: int DEFAULT: 1

perPage

How many results per page?

TYPE: int DEFAULT: 3

Source code in pymoe\anime\search\anilist.py
def studios(term: str, page: int = 1, perPage: int = 3):
    """
    Search for studios that match the term in the API.

    :param term: Search Term
    :param page: Which page of the results?
    :param perPage: How many results per page?
    """
    query_string = """\
        query($query: String, $page: Int, $perPage: Int){
            Page(page: $page, perPage: $perPage){
                pageInfo{
                    currentPage
                    hasNextPage
                }
                studios(search: $query){
                    id
                    name
                    siteUrl
                    media {
                        nodes {
                            id
                            idMal
                            title {
                                romaji
                                english
                                native
                            }
                            coverImage {
                                extraLarge
                                large
                                medium
                                color
                            }
                            siteUrl
                        }
                    }
                }
            }
        }
    """

    json_params = {
        "query": query_string,
        "variables": {"query": term, "page": page, "perPage": perPage},
    }

    r = requests.post(settings["apiurl"], headers=settings["header"], json=json_params)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if "errors" in jsd:
            raise serverError(r.text, r.status_code)
        else:
            if jsd["data"]["Page"]["pageInfo"]["hasNextPage"]:
                return anilistWrapper(
                    jsd["data"]["Page"]["studios"],
                    json_params,
                    settings["header"],
                    settings["apiurl"],
                )
            else:
                return jsd["data"]["Page"]["studios"]

pymoe.anime.search.kitsu

settings = {'header': {'Content-Type': 'application/vnd.api+json', 'User-Agent': 'Pymoe (github.com/ccubed/PyMoe)', 'Accept': 'application/vnd.api+json'}, 'apiurl': 'https://kitsu.io/api/edge'} module-attribute

characters(term)

Search for characters that match the term in the Kitsu API.

PARAMETER DESCRIPTION
term

Search Term

TYPE: str

Source code in pymoe\anime\search\kitsu.py
def characters(term: str):
    """
    Search for characters that match the term in the Kitsu API.

    :param term: Search Term
    """
    r = requests.get(
        settings["apiurl"] + "/characters",
        params={"filter[name]": term},
        headers=settings["header"],
    )

    if r.status_code != 200:
        raise serverError(r.text, r.status_code)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if jsd["meta"]["count"]:
            return kitsuWrapper(
                jsd["data"],
                jsd["links"]["next"] if "next" in jsd["links"] else None,
                settings["header"],
            )
        else:
            return jsd

season(season=None, seasonYear=date.today().year)

Given a season and a year, return a list of shows airing in that season and year. This can also pull historical and future data. (Though not too far in the future)

PARAMETER DESCRIPTION
season

Which Season? See pymoe.helpers for a list of seasons.

TYPE: str DEFAULT: None

seasonYear

What year?

TYPE: int DEFAULT: year

Source code in pymoe\anime\search\kitsu.py
def season(season: str = None, seasonYear: int = date.today().year):
    """
    Given a season and a year, return a list of shows airing in that season and year.
    This can also pull historical and future data. (Though not too far in the future)

    :param season: Which Season? See pymoe.helpers for a list of seasons.
    :param seasonYear: What year?
    """
    myseason = season if season else whatSeason(date.today().month)

    r = requests.get(
        settings["apiurl"] + "/anime",
        params={"filter[season]": myseason, "filter[seasonYear]": seasonYear},
        headers=settings["header"],
    )

    if r.status_code != 200:
        raise serverError(r.text, r.status_code)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if jsd["meta"]["count"]:
            return kitsuWrapper(
                jsd["data"],
                jsd["links"]["next"] if "next" in jsd["links"] else None,
                settings["header"],
            )
        else:
            return jsd

shows(term)

Search for shows that match the term in the Kitsu API.

PARAMETER DESCRIPTION
term

Search Term

TYPE: str

Source code in pymoe\anime\search\kitsu.py
def shows(term: str):
    """
    Search for shows that match the term in the Kitsu API.

    :param term: Search Term
    """
    r = requests.get(
        settings["apiurl"] + "/anime",
        params={"filter[text]": term},
        headers=settings["header"],
    )

    if r.status_code != 200:
        raise serverError(r.text, r.status_code)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if jsd["meta"]["count"]:
            return kitsuWrapper(
                jsd["data"],
                jsd["links"]["next"] if "next" in jsd["links"] else None,
                settings["header"],
            )
        else:
            return jsd

staff(term)

Kitsu doesn't support text filtering on the anime-staff endpoint. Method not supported.

Source code in pymoe\anime\search\kitsu.py
def staff(term: str):
    """
    Kitsu doesn't support text filtering on the anime-staff endpoint.
    Method not supported.
    """
    raise methodNotSupported("pymoe.anime.search.kitsu.staff", "kitsu")

streaming(item_id)

Given a media ID, return all streaming links related to that media. Unlike anilist, this returns one link per streaming service.

PARAMETER DESCRIPTION
item_id

ID to get streaming links for

TYPE: int

Source code in pymoe\anime\search\kitsu.py
def streaming(item_id: int):
    """
    Given a media ID, return all streaming links related to that media.
    Unlike anilist, this returns one link per streaming service.

    :param item_id: ID to get streaming links for
    """
    data = show(item_id)

    r = requests.get(
        data["data"]["relationships"]["streamingLinks"]["links"]["related"],
        headers=settings["header"],
    )

    if r.status_code != 200:
        raise serverError(r.text, r.status_code)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)
    else:
        if jsd["meta"]["count"]:
            return kitsuWrapper(
                jsd["data"],
                jsd["links"]["next"] if "next" in jsd["links"] else None,
                settings["header"],
            )
        else:
            return jsd

studios(term)

Kitsu doesn't support text filtering on the anime-producers endpoint. Method not supported.

Source code in pymoe\anime\search\kitsu.py
def studios(term: str):
    """
    Kitsu doesn't support text filtering on the anime-producers endpoint.
    Method not supported.
    """
    raise methodNotSupported("pymoe.anime.search.kitsu.studios", "kitsu")

pymoe.anime.search.mal

settings = {'header': {'Content-Type': 'application/json', 'User-Agent': 'Pymoe (github.com/ccubed/PyMoe)', 'Accept': 'application/json', 'X-MAL-CLIENT-ID': None}, 'apiurl': 'https://api.myanimelist.net/v2/', 'default_fields': 'id,title,main_picture,alternative_titles,start_date,end_date,synopsis,mean,rank,nsfw,genres,media_type,status,num_episodes,start_season,broadcast,source,rating,studios,related_anime,related_manga'} module-attribute

characters(term)

No endpoint exists for this at this time. Method not supported

Source code in pymoe\anime\search\mal.py
def characters(term: str):
    """
    No endpoint exists for this at this time.
    Method not supported
    """
    raise methodNotSupported("pymoe.anime.search.mal.characters", "myanimelist")

keyAssert()

This is just an assert. It cancels the request if the API Key is not present.

Source code in pymoe\anime\search\mal.py
def keyAssert():
    """
    This is just an assert. It cancels the request if the API Key is not present.
    """
    if (
        not settings["header"]["X-MAL-CLIENT-ID"]
        or type(settings["header"]["X-MAL-CLIENT-ID"]) != str
    ):
        raise ValueError("pymoe.anime.search.mal.keyAssert: API Key should be a string.")
    else:
        pass

season(season=None, seasonYear=date.today().year, limit=10, offset=0, nsfw=False)

Search for shows from a given season in a given year.

PARAMETER DESCRIPTION
season

Which season? See pymoe.helpers for a list.

TYPE: str DEFAULT: None

seasonYear

Which year?

TYPE: int DEFAULT: year

limit

How many results per page?

TYPE: int DEFAULT: 10

offset

Which result do we start at?

TYPE: int DEFAULT: 0

nsfw

Return adult results?

TYPE: bool DEFAULT: False

Source code in pymoe\anime\search\mal.py
def season(
    season: str = None,
    seasonYear: int = date.today().year,
    limit: int = 10,
    offset: int = 0,
    nsfw: bool = False,
):
    """
    Search for shows from a given season in a given year.

    :param season: Which season? See pymoe.helpers for a list.
    :param seasonYear: Which year?
    :param limit: How many results per page?
    :param offset: Which result do we start at?
    :param nsfw: Return adult results?
    """
    keyAssert()

    myseason = season or whatSeason(date.today().month)

    r = requests.get(
        settings["apiurl"] + "anime/season/{}/{}".format(seasonYear, myseason),
        params={
            "sort": "anime_score",
            "limit": limit,
            "offset": offset,
            "fields": "id,title,main_picture,alternative_titles,start_date,broadcast",
            "nsfw": "false" if not nsfw else "true",
        },
        headers=settings["header"],
    )

    if r.status_code != 200:
        raise serverError(r.text, r.status_code)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)

    rdict = [item["node"] for item in jsd["data"]]
    r_url = jsd["paging"]["next"] if "next" in jsd["paging"] else None

    return malWrapper(rdict, r_url, settings["header"])

shows(term, fields=None, limit=10, offset=0, nsfw=False)

Search for shows that match the given search term.

PARAMETER DESCRIPTION
term

Search Term

TYPE: str

fields

a comma separated list of fields to request from the API

TYPE: str | None DEFAULT: None

limit

How many results per page?

TYPE: int DEFAULT: 10

offset

Which result should we start at?

TYPE: int DEFAULT: 0

nsfw

Return adult results?

TYPE: bool DEFAULT: False

Source code in pymoe\anime\search\mal.py
def shows(
    term: str,
    fields: str | None = None,
    limit: int = 10,
    offset: int = 0,
    nsfw: bool = False,
):
    """
    Search for shows that match the given search term.

    :param term: Search Term
    :param fields: a comma separated list of fields to request from the API
    :param limit: How many results per page?
    :param offset: Which result should we start at?
    :param nsfw: Return adult results?
    """
    keyAssert()

    r = requests.get(
        settings["apiurl"] + "anime",
        params={
            "q": term,
            "fields": settings["default_fields"] or fields,
            "limit": limit,
            "offset": offset,
            "nsfw": "false" if not nsfw else "true",
        },
        headers=settings["header"],
    )

    if r.status_code != 200:
        raise serverError(r.text, r.status_code)

    try:
        jsd = ujson.loads(r.text)
    except ValueError:
        raise serializationFailed(r.text, r.status_code)

    rdict = [item["node"] for item in jsd["data"]]
    r_url = jsd["paging"]["next"] if "next" in jsd["paging"] else None

    return malWrapper(rdict, r_url, settings["header"])

staff(term)

No endpoint exists for this at this time. Method not supported

Source code in pymoe\anime\search\mal.py
def staff(term: str):
    """
    No endpoint exists for this at this time.
    Method not supported
    """
    raise methodNotSupported("pymoe.anime.search.mal.staff", "myanimelist")

studios(term)

No endpoint exists for this at this time. Method not supported

Source code in pymoe\anime\search\mal.py
def studios(term: str):
    """
    No endpoint exists for this at this time.
    Method not supported
    """
    raise methodNotSupported("pymoe.anime.search.mal.studios", "myanimelist")