Ejemplo n.º 1
0
    def post(self):
        result = {"error": None, "data": {}}

        parser = reqparse.RequestParser()
        parser.add_argument("franchises",
                            type=list,
                            default=[],
                            location="json")
        parser.add_argument("subtitles",
                            type=list,
                            default=[],
                            location="json")
        parser.add_argument("voiceover",
                            type=list,
                            default=[],
                            location="json")
        parser.add_argument("aliases", type=list, default=[], location="json")
        parser.add_argument("genres", type=list, default=[], location="json")
        parser.add_argument("description", type=str, required=True)
        parser.add_argument("category", type=str, required=True)
        parser.add_argument("title", type=dict, required=True)
        parser.add_argument("team", type=str, required=True)
        parser.add_argument("year", type=int, required=True)
        parser.add_argument("state", type=str, default=None)
        args = parser.parse_args()

        title_parser = reqparse.RequestParser()
        title_parser.add_argument("jp",
                                  type=str,
                                  default=None,
                                  location=("title", ))
        title_parser.add_argument("ua", type=str, location=("title", ))
        title_args = title_parser.parse_args(req=args)

        for alias in args["aliases"]:
            if type(alias) is not str:
                return abort("general", "alias-invalid-type")

        team = TeamService.get_by_slug(args["team"])
        if team is None:
            return abort("team", "not-found")

        if request.account not in team.members:
            return abort("account", "not-team-member")

        if not PermissionService.check(request.account, "global",
                                       "publishing"):
            return abort("account", "permission")

        category = DescriptorService.get_by_slug("category", args["category"])
        if category is None:
            return abort("category", "not-found")

        state = DescriptorService.get_by_slug("state", args["state"])
        if state is None:
            return abort("state", "not-found")

        if args["description"] is None:
            return abort("general", "missing-field")

        genres = []
        for slug in args["genres"]:
            genre = DescriptorService.get_by_slug("genre", slug)
            if genre is not None:
                genres.append(genre)
            else:
                return abort("genre", "not-found")

        franchises = []
        for slug in args["franchises"]:
            franchise = DescriptorService.get_by_slug("franchise", slug)
            if franchise is not None:
                franchises.append(franchise)
            else:
                return abort("franchise", "not-found")

        subtitles = []
        for username in args["subtitles"]:
            subtitles_account = UserService.get_by_username(username)
            if subtitles_account is not None:
                subtitles.append(subtitles_account)

            else:
                return abort("account", "not-found")

        voiceover = []
        for username in args["voiceover"]:
            voiceover_account = UserService.get_by_username(username)
            if voiceover_account is not None:
                voiceover.append(voiceover_account)

            else:
                return abort("account", "not-found")

        title = AnimeService.get_title(title_args["ua"], title_args["jp"])
        search = utils.create_search(title_args["ua"], title_args["jp"],
                                     args["aliases"])
        slug = utils.create_slug(title_args["ua"])

        anime = AnimeService.create(title, slug, args["description"],
                                    args["year"], search, category, state,
                                    genres, franchises, [team], subtitles,
                                    voiceover, args["aliases"])

        result["data"] = anime.dict()
        return result
Ejemplo n.º 2
0
from hikka.tools import helpers
from jikanpy import Jikan
from hikka import utils
import time

jikan = Jikan()
top = jikan.top(type="anime")

for index, item in enumerate(top["top"]):
    data = jikan.anime(item["mal_id"])
    myanimelist = data["mal_id"]

    if data["synopsis"] is None:
        data["synopsis"] = "Lorem ipsum dolor sit amet."

    title = AnimeService.get_title(data["title"])
    anime = AnimeService.create(title, data["synopsis"],
                                helpers.category(data["type"].lower()),
                                helpers.state("released"),
                                utils.create_slug(data["title"]))

    anime.search = utils.create_search(anime.title.ua, data["title_synonyms"])
    anime.external = AnimeService.get_external(myanimelist)
    anime.year = data["aired"]["prop"]["from"]["year"]
    anime.teams = [helpers.team("fanvox")]
    anime.aliases = data["title_synonyms"]
    anime.total = data["episodes"]
    anime.rating = data["score"]

    for genre_data in data["genres"]:
        genre_slug = genre_data["name"].lower().replace("-",
Ejemplo n.º 3
0
def new_anime():
    result = {"error": None, "data": {}}

    parser = RequestParser()
    parser.argument("franchises", type=list, default=[], location="json")
    parser.argument("subtitles", type=list, default=[], location="json")
    parser.argument("voiceover", type=list, default=[], location="json")
    parser.argument("aliases", type=list, default=[], location="json")
    parser.argument("genres", type=list, default=[], location="json")
    parser.argument("category", type=helpers.category, required=True)
    parser.argument("description", type=helpers.string, required=True)
    parser.argument("state", type=helpers.state, required=True)
    parser.argument("team", type=helpers.team, required=True)
    parser.argument("season", type=int, choices=range(1, 5))
    parser.argument("title", type=dict, required=True)
    parser.argument("year", type=int, required=True)
    parser.argument("external", type=dict)
    parser.argument("total", type=int)
    args = parser.parse()

    title_parser = RequestParser()
    title_parser.argument("ua",
                          type=helpers.string,
                          location="title",
                          required=True)
    title_parser.argument("jp", type=helpers.string, location="title")
    title_args = title_parser.parse(req=args)

    external_parser = RequestParser()
    external_parser.argument("myanimelist", type=int, location="external")
    external_parser.argument("toloka", type=int, location="external")
    external_args = external_parser.parse(req=args)

    title = AnimeService.get_title(title_args["ua"], title_args["jp"])
    slug = utils.create_slug(title_args["ua"])
    team = args["team"]

    helpers.is_member(request.account, [team])

    anime = AnimeService.create(title, args["description"], args["category"],
                                args["state"], slug)

    for alias in args["aliases"]:
        if type(alias) is not str:
            return abort("general", "alias-invalid-type")

    anime.genres = []
    for slug in args["genres"]:
        genre = helpers.genre(slug)
        anime.genres.append(genre)

    anime.franchises = []
    for slug in args["franchises"]:
        franchise = helpers.franchise(slug)
        anime.franchises.append(franchise)

    fields = ["aliases", "year", "total"]
    for field in fields:
        anime[field] = args[field]

    fields = ["subtitles", "voiceover"]
    for field in fields:
        anime[field] = []
        for username in args[field]:
            account = helpers.account(username)
            anime[field].append(account)

    search = utils.create_search(anime.title.ua, anime.title.jp, anime.aliases)
    external = AnimeService.get_external(external_args["myanimelist"],
                                         external_args["toloka"])

    anime.external = external
    anime.search = search
    anime.teams = [team]

    if anime.external.myanimelist:
        anime.rating = utils.rating(anime.external.myanimelist)
        anime.save()

    result["data"] = anime.dict()
    anime.save()

    return result