Пример #1
0
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("-",
                                                        "_").replace(" ", "_")
        try:
            anime.genres.append(helpers.genre(genre_slug))
        except Exception:
            pass

    file = FileService.create(None, helpers.account("volbil"))
Пример #2
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