示例#1
0
文件: aniname.py 项目: s1as3r/Skripts
def get_all_eps(name: str, select: int = 0) -> Dict[int, Tuple[str, bool]]:
    """
    `str` `name`: Name of the anime.
    `bool` `select_first`: Instead of showing the prompt, select the `select` result.

    RETURNS `Dict<int, Tuple<str, bool>>`: A dictionary containing an
    episode's name and filler info.

    Get all the episodes of an anime.
    """
    client = Jikan()

    results = client.search("anime", name)["results"][:10]
    anime = {i: j for i, j in enumerate(results, 1)}
    if select == 0:
        prompt = "\n".join(f"{n:0>2} => {t['title']}"
                           for n, t in anime.items())
        select = input(prompt + "\nSelect Anime: ")
    anime_id = anime[int(select)]["mal_id"]
    selected_anime = client.anime(anime_id, extension="episodes")
    eps = selected_anime["episodes"]
    eps_len = selected_anime["episodes_last_page"]
    if eps_len != 1:
        for i in range(2, eps_len + 1):
            eps.extend(
                client.anime(anime_id, extension="episodes",
                             page=i)["episodes"])

    ep_dict = {i["episode_id"]: [i["title"], i["filler"]] for i in eps}
    return ep_dict
示例#2
0
def rating(code):
    try:
        jikan = Jikan()
        data = jikan.anime(code)
        return data["score"]
    except Exception:
        return 0
示例#3
0
class MyAnimeList(AnimeInformationProvider):
    def __init__(self):
        self.jikan = Jikan()
        self.logger = logging.getLogger(self.__class__.__name__)

    def anime_to_characters_names(self, anime_name: str):
        animes = self.jikan.search('anime', anime_name)['results']
        if not animes:
            raise Exception('Could not find anime: {}'.format(anime_name))
        anime = animes[0]
        anime_title = anime['title']
        self.logger.debug('Found anime: %s.', anime_title)

        characters = self.jikan.anime(
            anime['mal_id'], extension='characters_staff')['characters']
        self.logger.debug('Found %s characters for the anime: %s.',
                          len(characters), anime_title)
        names = []
        for character in characters:
            full_name = character['name']
            name_parts = full_name.split(',')
            if len(name_parts) == 2:
                last_name = name_parts[0]
                first_name = name_parts[1]
                names.append(Name(last_name=last_name, first_name=first_name))
        return names
示例#4
0
def get_characters_for_anime_id(mal_id: int) -> Optional[list[AnimeCharacter]]:
    jikan = Jikan()
    try:
        res = jikan.anime(mal_id, extension="characters_staff")
    except jikanpy.APIException:
        print(f"Character api error for {mal_id=}")
        return None
    chars_list = res["characters"]
    result_chars_list = [AnimeCharacter.from_api(char) for char in chars_list]
    return result_chars_list
示例#5
0
def search_anime(s):
    jikan = Jikan()
    results = jikan.search('anime', s)

    result = {}

    print(CGREEN + "[Mai] These are the top results I found." + CEND)

    for idx, resultitems in enumerate(results['results'], start=1):
        print("\t" + CRED + str(idx) + ". " +
              wrapper.fill(resultitems['title']) + CEND)
        # storing mal_id for later use
        result[idx] = resultitems['mal_id']

    # to check if everything is working as expected
    # print(result)

    print(
        CGREEN +
        "[Mai] Type the index of the anime you want information on or type 0 to exit: "
        + CEND,
        end=' ')
    idx = int(input())

    if (idx == 0):
        return

    results = jikan.anime(result[idx])
    print(
        CGREEN +
        "[Mai] This is the information I found on the requested anime (press q to exit imageviewer)"
        + CEND)

    # sanity check
    # print(results)

    # downloading image and storing in cache
    f = open('cachepic.jpg', 'wb')
    f.write(urllib.request.urlopen(results['image_url']).read())
    f.close()

    # ugh i don't like this hack. depends too much on system and imageviewer installed. try to fix this later.
    subprocess.call(["feh", "-x", "cachepic.jpg"])

    title = results['title']
    episodes = results['episodes']
    status = results['status']
    # returns as list
    title_syns = results['title_synonyms']
    date = results['aired']['string']
    syn = results['synopsis']
    score = results['score']

    printnicely(title, title_syns, score, status, syn, episodes, date)
def parse_no_user_info(list_to_parse):
    fields = [
        'ID', 'Image Url', 'Title', 'Episodes', 'Rating', 'Score', 'Rank',
        'Popularity', 'Members', 'Favorites', 'Adaption_Size', 'Producers',
        'Studios', 'Genres', 'Type', 'Status'
    ]
    jikan = Jikan()

    with open(csv_file_name, 'a') as csv_file:
        writer = csv.DictWriter(csv_file, fieldnames=fields)

        if csv_file.tell() == 0:
            writer.writeheader()

        for anime_id in list_to_parse:
            try:
                # 2 seconds per request
                time.sleep(2)
                # write anime info to csv file
                anime = jikan.anime(anime_id)
                content = {}
                content['ID'] = anime_id
                content['Image Url'] = anime['image_url']
                content['Title'] = anime['title_english']
                content['Episodes'] = anime['episodes']
                content['Rating'] = anime['rating']
                content['Score'] = anime['score']
                content['Rank'] = anime['rank']
                content['Popularity'] = anime['popularity']
                content['Members'] = anime['members']
                content['Favorites'] = anime['favorites']
                if 'Adaptation' in anime['related']:
                    content['Adaption_Size'] = len(
                        anime['related']['Adaptation'])
                else:
                    content['Adaption_Size'] = 0

                content['Producers'] = extract_list_info(
                    anime['producers'], 'name')
                content['Studios'] = extract_list_info(anime['studios'],
                                                       'name')
                content['Genres'] = extract_list_info(anime['genres'], 'name')

                content['Type'] = anime['type']
                content['Status'] = anime['status']

                print(content)
                writer.writerow(content)
            except exceptions.APIException:
                print("anime id " + str(anime_id) + " does not exist")
            except:
                print("failure at " + str(anime_id))
                raise
示例#7
0
class CachedJikan():
    def __init__(self, username):
        self._jikan = Jikan()
        self._last_request_time = time.time()
        self._REQUEST_DELAY = 2
        self._mal_username = username
        self._animelist_watching = None
        self._animelist_watching_time = None
        self._animes = dict()

    def _request_wait_time(self):
        return max(0, (self._last_request_time + self._REQUEST_DELAY) -
                   time.time())

    def _delay_request(self, request_func):
        time.sleep(self._request_wait_time())
        result = request_func()
        self._last_request_time = time.time()
        return result

    def animelist_watching(self):
        if self._animelist_watching is None or time.time(
        ) - self._animelist_watching_time > 5 * 60:
            try:

                def do_request():
                    return self._jikan.user(username=self._mal_username,
                                            request='animelist',
                                            argument='watching')

                self._animelist_watching = self._delay_request(do_request)
                self._animelist_watching_time = time.time()
            except APIException as e:
                LOG.error('exception getting watchlist')
                LOG.error(e)
        return self._animelist_watching

    def anime(self, anime_id):
        if anime_id not in self._animes:
            try:

                def do_request():
                    return self._jikan.anime(anime_id)

                anime = self._delay_request(do_request)
                self._animes[anime_id] = anime
            except APIException as e:
                LOG.error(str.format('exception getting anime id:{}',
                                     anime_id))
                LOG.error(e)
                return None
        return self._animes[anime_id]
示例#8
0
def get_ptw_info(anime_list: Iterable[Anime]) -> List[PTWEntry]:
    """Store PTW of each anime in a list of tuples"""
    jikan = Jikan()
    ptw = list()

    print("Requesting ptw via Jikan")
    for anime in anime_list:
        print(f"Looking up stats for {anime.name}")
        anime_stats = jikan.anime(anime.id, extension="stats")
        anime_ptw_num = localize_number(anime_stats["plan_to_watch"])
        ptw.append(PTWEntry(anime.name, anime.id, anime_ptw_num))
        time.sleep(config.getint("jikanpy", "request-interval"))
    return ptw
示例#9
0
def getInfoFromDatabase(allShows):

    jikan = Jikan()
    Database = mysql.connector.connect(host="127.0.0.1",
                                       user="******",
                                       passwd="python",
                                       database="streaming")

    cursor = Database.cursor(buffered=True)
    c = 0

    for CShows in allShows:
        print("current: " + CShows)
        cursor.execute("SELECT * FROM series WHERE SeriesName=%s", (CShows, ))
        fetch = cursor.fetchone()
        if getIFCheck(fetch):
            search_result = jikan.search('anime', CShows)
            try:
                if len(search_result) >= 1:

                    Mal_id = str(search_result['results'][0]['mal_id'])
                    anime = jikan.anime(Mal_id)
                    sql = ""
                    execute = True
                    val = None
                    if fetch != None:
                        if anime['status'] == "Currently Airing":
                            execute = False
                        sql = "UPDATE customers SET seriesStatus = %s WHERE id = %s"
                        val = (anime['status'], fetch[0])
                        print("Show Updated !")

                    else:
                        sql = "INSERT INTO series (seriesName, JapaneseName, genres, seriesStatus, Description, episodeCount, ImageURL, LargeImageURL, malID, trailer, aired, duration, type ) VALUES (%s, %s, %s, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
                        val = (CShows, anime['title_japanese'],
                               GetGenres(anime), anime['status'],
                               anime['synopsis'], anime['episodes'],
                               anime['image_url'], anime['image_url'].replace(
                                   ".jpg", "l.jpg"), Mal_id,
                               anime['trailer_url'], anime['premiered'],
                               anime['duration'], anime['type'])

                    if execute:
                        cursor.execute(sql, val)
                        Database.commit()
            except:
                print("error at: " + CShows)

    getSchedule(cursor, Database)
示例#10
0
 def get_json(self, req_anime_list, season, year):
     jikan = Jikan()
     animes_this_season = jikan.season(year=year, season=season)
     animes = []
     for anime in animes_this_season['anime']:
         for req_anime in req_anime_list:
             if anime['title'] == req_anime['name']:
                 anime_details = jikan.anime(anime['mal_id'])
                 ani = copy.deepcopy(anime)
                 ani['torrentname'] = req_anime['torrentname']
                 ani['quality'] = req_anime['quality']
                 ani['search_queries'] = self.create_search_queries(
                     req_anime, anime_details)
                 ani['have_prequel'] = self.check_new_anime(anime_details)
                 ani['folder_name'] = req_anime['folder_name']
                 animes.append(ani)
     return animes
示例#11
0
def main():
    "Use Jikan API to update the database with new anime entries"
    "New anime ids from MAL are gathered from mal-id-cache repo"
    conn = connect_to_db()
    db_ids = get_all_ids_from_db(conn)
    cache_ids = get_ids_from_mal_id_cache()
    left_over_ids = [
        cached_id for cached_id in cache_ids if cached_id not in db_ids
    ]
    print(len(left_over_ids))

    jikan = Jikan()
    for anime_id in left_over_ids:
        try:
            anime = jikan.anime(anime_id)
        except jikanpy.exceptions.APIException:
            continue
        add_jikan_response_to_db(conn, anime)
        time.sleep(2)

    conn.close()
示例#12
0
class MyAnimeListService():
    def __init__(self):
        self.jk = Jikan()
    def get_anime(self,anime_name):
        # BUSCAMOS EL ANIME
        result = self.jk.search("anime",anime_name,parameters={"limit": 1})
        anime_data = self.jk.anime(result["results"][0]["mal_id"])
        anime = {}
        ## OBTENEMOS NADA MAS LA INOFMRACIÓN QUE NECESITAMOS
        anime["title"] = anime_data["title"] # TITULO
        anime["episodes"] = anime_data["episodes"] # EPISODIOS
        anime["airing"] = "🔴 Finished Airing" if not anime_data["airing"] else "✅ Currently Airing" # Al aire
        ## SCORE con emoji
        if anime_data["score"]>7.5:
            score = "%s 😍"%anime_data["score"]
        elif 5<anime_data["score"]<=7.5:
            score = "%s 🙂"%anime_data["score"]
        elif 2.5<anime_data["score"]<=5:
            score = "%s 😞"%anime_data["score"]
        elif anime_data["score"]<=2.5:
            score = "%s 😠"%anime_data["score"]
        anime["score"] = score # Score
        anime["date"] = "%s"%anime_data["aired"]["from"][:10] #Fecha en que se publico
        anime["rated"] = anime_data["rating"] # Rating
        anime["synopsis"] = anime_data["synopsis"] # Sinpopsis
        anime["background"] = anime_data["background"] # Contexto
        anime["genres"] = ", ".join([x["name"] for x in anime_data["genres"] ]) # Generos
        anime["ranked"] = str(anime_data["rank"]) # Rank en MAL
        anime["trailer"] = anime_data["trailer_url"] # URL del trailer
        # Tratamos de obtener su imagen
        try:
            regex = re.search(r"\.jpg",anime_data["image_url"])
            anime["image"] = anime_data["image_url"][:regex.end()]
        except:
            anime["image"] = None
        return anime
示例#13
0
class MyAnimeListService():
    def __init__(self):
        self.jk = Jikan()

    def search(self, m):
        m.m_type = "text"
        print("searching %s" % m.text)
        result = self.jk.search("anime", m.text, parameters={"limit": 5})
        print("finish")
        names = ["- %s\n" % x["title"] for x in result["results"]]
        m.text = "Resultados:\n" + "".join(names)
        return m

    def getAnime(self, m):
        result = self.jk.search("anime", m.text, parameters={"limit": 1})
        anime = result["results"][0]
        title = "*%s*" % anime["title"]
        episodes = "Episodes: %s" % anime["episodes"]
        airing = "🔴 Finished Airing" if not anime[
            "airing"] else "✅ Currently Airing"
        if anime["score"] > 7.5:
            score = "Score: %s 😍" % anime["score"]
        elif 5 < anime["score"] <= 7.5:
            score = "Score: %s 🙂" % anime["score"]
        elif 2.5 < anime["score"] <= 5:
            score = "Score: %s 😞" % anime["score"]
        elif anime["score"] <= 2.5:
            score = "Score: %s 😠" % anime["score"]
        date = "Date: %s" % anime["start_date"][:10]
        rated = "Rated: %s" % anime["rated"]
        synopsis = "Synopsis: %s" % anime["synopsis"]
        m.text = "%s\n%s\n%s\n%s\n%s\n%s\n%s\n" % (
            title, episodes, airing, score, date, rated, synopsis)
        try:
            regex = re.search(r"\.jpg", anime["image_url"])
            m.img = anime["image_url"][:regex.end()]
            m.m_type = "img"
        except:
            m.m_type = "text"
        return m

    def getAllInfo(self, m):
        result = self.jk.search("anime", m.text, parameters={"limit": 1})
        anime = self.jk.anime(result["results"][0]["mal_id"])
        title = "*%s*" % anime["title"]
        episodes = "Episodes: %s" % anime["episodes"]
        airing = "🔴 Finished Airing" if not anime[
            "airing"] else "✅ Currently Airing"
        if anime["score"] > 7.5:
            score = "Score: %s 😍" % anime["score"]
        elif 5 < anime["score"] <= 7.5:
            score = "Score: %s 🙂" % anime["score"]
        elif 2.5 < anime["score"] <= 5:
            score = "Score: %s 😞" % anime["score"]
        elif anime["score"] <= 2.5:
            score = "Score: %s 😠" % anime["score"]
        date = "Date: %s" % anime["aired"]["from"][:10]
        rated = "Rated: %s" % anime["rating"]
        synopsis = "Synopsis: %s" % anime["synopsis"]
        background = "Background: %s" % anime["background"]
        genres = "Genres:" + ", ".join([x["name"] for x in anime["genres"]])
        ranked = "Ranked: " + str(anime["rank"])
        trailer = "Trailer: " + anime["trailer_url"]
        data = (title, genres, episodes, airing, score, ranked, date, rated,
                synopsis, background, trailer)
        m.text = "%s\n" * len(data)
        m.text = m.text % data
        try:
            regex = re.search(r"\.jpg", anime["image_url"])
            m.img = anime["image_url"][:regex.end()]
            m.m_type = "img"
        except:
            m.m_type = "text"
        return m
def main(num_id_visited):

    fields = [
        'ID', 'Image Url', 'Title', 'Episodes', 'Rating', 'Score', 'Rank',
        'Popularity', 'Members', 'Favorites', 'Adaption_Size', 'Producers',
        'Studios', 'Genres', 'Type', 'Status'
    ]
    review_fields = [
        'Anime ID', 'Username', 'Scores_overall', 'Scores_story',
        'Scores_animation', 'Scores_sound', 'Scores_character',
        'Scores_enjoyment'
    ]
    jikan = Jikan()
    user_name_set = set()

    with open(csv_file_name, 'a') as csv_file:
        with open(csv_reviews_file_name, 'a') as csv_reviews_file:
            writer = csv.DictWriter(csv_file, fieldnames=fields)
            reviews_writer = csv.DictWriter(csv_reviews_file,
                                            fieldnames=review_fields)

            if csv_file.tell() == 0:
                writer.writeheader()
            if csv_reviews_file.tell() == 0:
                reviews_writer.writeheader()

            i = 0
            while i < num_id_visited:
                anime_id = start_id + i
                try:
                    #2 seconds per request
                    time.sleep(3)
                    #write anime info to csv file
                    anime = jikan.anime(anime_id)
                    content = {}
                    content['ID'] = anime_id
                    content['Image Url'] = anime['image_url']
                    content['Title'] = anime['title_english']
                    content['Episodes'] = anime['episodes']
                    content['Rating'] = anime['rating']
                    content['Score'] = anime['score']
                    content['Rank'] = anime['rank']
                    content['Popularity'] = anime['popularity']
                    content['Members'] = anime['members']
                    content['Favorites'] = anime['favorites']
                    if 'Adaptation' in anime['related']:
                        content['Adaption_Size'] = len(
                            anime['related']['Adaptation'])
                    else:
                        content['Adaption_Size'] = 0

                    content['Producers'] = extract_list_info(
                        anime['producers'], 'name')
                    content['Studios'] = extract_list_info(
                        anime['studios'], 'name')
                    content['Genres'] = extract_list_info(
                        anime['genres'], 'name')

                    content['Type'] = anime['type']
                    content['Status'] = anime['status']

                    print(content)
                    writer.writerow(content)

                    #parse user info
                    for j in range(25):
                        time.sleep(2)
                        anime_reviews = jikan.anime(anime_id,
                                                    extension='reviews',
                                                    page=j + 1)
                        print("get " + str(len(anime_reviews['reviews'])) +
                              " results")
                        for review in anime_reviews['reviews']:

                            review_info = {}
                            reviewer = review['reviewer']
                            user_name_set.add(reviewer['username'])
                            review_info['Anime ID'] = str(start_id + i)
                            review_info['Username'] = reviewer['username']
                            review_info['Scores_overall'] = reviewer['scores'][
                                'overall']
                            review_info['Scores_story'] = reviewer['scores'][
                                'story']
                            review_info['Scores_animation'] = reviewer[
                                'scores']['animation']
                            review_info['Scores_sound'] = reviewer['scores'][
                                'sound']
                            review_info['Scores_character'] = reviewer[
                                'scores']['character']
                            review_info['Scores_enjoyment'] = reviewer[
                                'scores']['enjoyment']
                            reviews_writer.writerow(review_info)

                        if len(anime_reviews['reviews']) < 20:
                            break

                    i += 1

                except exceptions.APIException:
                    print("anime id " + str(anime_id) + " does not exist")
                    i += 1
                except:
                    print("failure at " + str(anime_id))
                    print("Have collected " + str(len(user_name_set)) +
                          " usernames")
                    pickle.dump(user_name_set, open(pickle_file_name, "wb"))
                    raise

    pickle.dump(user_name_set, open(pickle_file_name, "wb"))
    print("Have collected " + str(len(user_name_set)) + " usernames")
class Recomender:
    def __init__(self, user_name):
        self.user_name: str = user_name  # MAL username
        self.jikan = Jikan()  # API object

        self.anime_dic = {}  # dic of anime id and it's score
        self.genre_dic = defaultdict(
            list)  # dic of genres and a list of user scores for them
        self.studio_dic = defaultdict(
            list)  # dic of studios and a list of user scores for them
        self.source_material_dic = defaultdict(
            list)  # dic of source materials and a list of user scores for them
        self.type_dic = defaultdict(
            list)  # dic of types and a list of user scores for them
        self.episodes_amount_dic = defaultdict(
            list
        )  # dic of episode amount enums and a list of user scores for them
        self.staff_dic = defaultdict(
            list)  # dic of staff people and a list of user scores for them

        self.analyzed_anime_dic = {
        }  # dic of analyzed seasonal anime and their scores
        self.anime_name_dic = {}  # dic of MAL anime ids and names
        self.staff_name_dic = {}  # dic of MAL staff ids and names

    """
    Fills the anime_dic with the users rated anime
    """

    def fill_anime_dic(self):
        print("Started filling anime dic.")
        last_page: bool = False
        page_num: int = 1

        while not last_page:  # the API only returns 300 anime so we may need to request multiple pages
            animelist = self.jikan.user(username=self.user_name,
                                        request='animelist',
                                        argument="all",
                                        page=page_num)
            if animelist["request_cached"] is False:
                time.sleep(
                    SLEEP_TIME
                )  # if the request was uncached we need to add a delay or we get a 429
            for anime in animelist["anime"]:
                if anime["score"] > 0:  # only add the anime if the user set a score
                    self.anime_dic[anime["mal_id"]] = anime["score"]
            if len(animelist["anime"]
                   ) < 300:  # each page contains max 300 anime
                last_page = True
            page_num += 1

    """
    Gathers data like genre or studio scores based upon the anime in the anime dic
    """

    def gather_anime_data_from_anime_dic(self):
        print("Started gathering anime data from anime dic.")
        progress_counter = 1
        for animeID in self.anime_dic.keys():  # go though every anime
            if progress_counter % 10 == 1:
                print("Gathered " + str(progress_counter) + " anime.")
            progress_counter += 1

            anime = self.jikan.anime(animeID)
            if anime["request_cached"] is False:
                time.sleep(SLEEP_TIME)  # sleep to prevent 429
            anime_staff_full = self.jikan.anime(
                animeID, extension='characters_staff')  # get staff data
            anime_staff = anime_staff_full["staff"]
            if anime_staff_full["request_cached"] is False:
                time.sleep(SLEEP_TIME)
            score = self.anime_dic[animeID]

            for genre in anime["genres"]:  # add score for every genre
                self.genre_dic[genre["mal_id"]].append(score)

            for studio in anime["studios"]:  # add score for every studio
                self.studio_dic[studio["mal_id"]].append(score)

            self.source_material_dic[anime["source"]].append(
                score)  # add score for source material
            self.type_dic[anime["type"]].append(score)  # add score for type

            episodes = anime["episodes"]
            if episodes is None:  # if episodes are unset set the to zero
                episodes = 0
            if episodes > 0:  # only add score if episodes are set
                episodes_enum = self.get_episode_amount_enum(episodes)
                self.episodes_amount_dic[episodes_enum].append(score)

            for staff_member in anime_staff:
                for position in staff_member["positions"]:
                    #  only add the staff member if their position is relevant according to my own decision
                    if position in POSITION_SET:
                        self.staff_dic[staff_member["mal_id"]].append(score)
                        self.staff_name_dic[
                            staff_member["mal_id"]] = staff_member["name"]

    """
    analyzes the anime of a specific season with the data gathered from the user
    year = int, year of the season
    season = string, season of the year (either winter, spring, summer or fall)
    kids = boolean, if you want to analyze kids shows
    r18 = if you want to analyze r18 (hentai) shows
    """

    def analyze_seasonal_anime(self, year, season, kids, r18):
        seasonal_anime_full = self.jikan.season(year=year, season=season)
        if seasonal_anime_full["request_cached"] is False:
            time.sleep(SLEEP_TIME)
        seasonal_anime = seasonal_anime_full["anime"]
        print("Started analyzing seasonal anime.")
        progress_counter = 1
        for anime in seasonal_anime:
            if progress_counter % 10 == 1:
                print("Analyzed " + str(progress_counter) + " anime.")
            progress_counter += 1

            if anime[
                    "continuing"]:  # if the anime is actually from a previous season, don't analyze it
                continue
            if not r18 and anime["r18"]:
                continue
            if not kids and anime["kids"]:
                continue
            self.analyze_anime(anime)

    """
    analyzes an anime and puts it and the score to the analyzed anime dic
    anime = either an anime object or the MAL ID as an int
    """

    def analyze_anime(self, anime):
        if isinstance(anime,
                      int):  # if anime is an int get the anime object of it
            anime = self.jikan.anime(anime)

        score_divisor = 0  # variable through which the score in the end will be divided so that we get one that goes from 1 to 10 by adding the FACTOR of a value

        anime_staff_full = self.jikan.anime(anime["mal_id"],
                                            extension='characters_staff')
        if anime_staff_full["request_cached"] is False:
            time.sleep(SLEEP_TIME)
        anime_staff = anime_staff_full["staff"]
        score = 0.0
        score_addition_counter = 0  # count how many scores were actually added to the score

        genre_amount = 0
        genre_score = 0.0
        for genre in anime["genres"]:
            if genre["mal_id"] in self.genre_dic.keys():
                genre_amount += 1
                # get the average of the scores in the list
                genre_score += sum(self.genre_dic[genre["mal_id"]]) / len(
                    self.genre_dic[genre["mal_id"]])
        if genre_amount > 0:  # only add if there was atleast one genre
            score += genre_score / genre_amount * GENRE_FACTOR
            score_addition_counter += 1
            score_divisor += GENRE_FACTOR

        studio_amount = 0
        studio_score = 0.0
        for studio in anime["producers"]:
            if studio["mal_id"] in self.studio_dic.keys():
                studio_amount += 1
                studio_score += sum(self.studio_dic[studio["mal_id"]]) / len(
                    self.studio_dic[studio["mal_id"]])
        if studio_amount > 0:
            score += studio_score / studio_amount * STUDIO_FACTOR
            score_addition_counter += 1
            score_divisor += STUDIO_FACTOR

        if anime["source"] in self.source_material_dic:
            source_score = sum(
                self.source_material_dic[anime["source"]]) / len(
                    self.source_material_dic[anime["source"]])
            if source_score > 0:
                score += source_score * SOURCE_MATERIAL_FACTOR
                score_addition_counter += 1
                score_divisor += SOURCE_MATERIAL_FACTOR

        if anime["type"] in self.type_dic:
            type_score = sum(self.type_dic[anime["type"]]) / len(
                self.type_dic[anime["type"]])
            if type_score > 0:
                score += type_score * TYPE_FACTOR
                score_addition_counter += 1
                score_divisor += TYPE_FACTOR

        episode_amount = anime["episodes"]
        if episode_amount is None:  # check if episodes are set and if they are not set them to 0
            episode_amount = 0
        if episode_amount > 0:
            episode_enum = self.get_episode_amount_enum(episode_amount)
            if episode_enum in self.episodes_amount_dic:
                episode_amount_score = sum(
                    self.episodes_amount_dic[episode_enum]) / len(
                        self.episodes_amount_dic[episode_enum])
                if episode_amount_score > 0:
                    score += episode_amount_score * EPISODE_AMOUNT_FACTOR
                    score_addition_counter += 1
                    score_divisor += EPISODE_AMOUNT_FACTOR

        staff_score = 0.0
        staff_amount = 0
        for staff_member in anime_staff:
            if staff_member["mal_id"] in self.staff_dic:
                staff_amount += 1
                staff_score += sum(
                    self.staff_dic[staff_member["mal_id"]]) / len(
                        self.staff_dic[staff_member["mal_id"]])
        if staff_amount > 0:
            staff_score /= staff_amount
            score += staff_score * STAFF_FACTOR
            score_addition_counter += 1
            score_divisor += STAFF_FACTOR

        if score_addition_counter > 0:
            self.anime_name_dic[anime["mal_id"]] = anime["title"]
            self.analyzed_anime_dic[anime["mal_id"]] = (
                (score / score_addition_counter) *
                (0.4 + 0.1 * score_addition_counter)) / (
                    score_divisor / score_addition_counter
                )  # calculate the score and add the anime to the dic

    """
    writes a comma seperated value file with the result of the analyzed seasonal anime
    """

    def write_analyzed_anime_to_file(self):
        with open("analyzed_anime.txt", mode="w",
                  encoding="utf8") as text_file:
            text_file.write("Name^MAL ID^Score\n")
            for anime in self.analyzed_anime_dic.keys():
                text_file.write(
                    str(self.anime_name_dic[anime]) + "^" + str(anime) + "^" +
                    str(self.analyzed_anime_dic[anime]) + "\n")
        print("Done writing anime file!")

    """
    writes a comma seperated value file with staff members and their score
    """

    def write_analyzed_staff_to_file(self):
        with open("analyzed_staff.txt", mode="w",
                  encoding="utf8") as text_file:
            text_file.write("Name^MAL ID^Average^Amount^Score\n")

            max_len = -1
            for staff in self.staff_dic.keys():
                if len(self.staff_dic[staff]) > max_len:
                    max_len = len(self.staff_dic[staff])

            for staff in self.staff_dic.keys():
                FACTOR = 0.866
                length = len(self.staff_dic[staff])
                scores_list = self.staff_dic[staff]
                average = sum(scores_list) / length
                text_file.write(
                    str(self.staff_name_dic[staff]) + "^" + str(staff) + "^" +
                    str(average) + "^" + str(length) + "^" +
                    str(average * FACTOR + ((length / max_len) *
                                            (1.0 - FACTOR) * 10.0)) + "\n")
        print("Done writing staff file!")

    """
    A Function that returns an Enum for summarizing episode amounts
    """

    @staticmethod
    def get_episode_amount_enum(amount) -> EpisodesAmount:
        if amount < 1:
            return None
        elif amount == 1:
            return EpisodesAmount.One
        elif 2 <= amount <= 8:
            return EpisodesAmount.TwoEight
        elif 9 <= amount <= 19:
            return EpisodesAmount.NineNineteen
        elif 20 <= amount <= 30:
            return EpisodesAmount.TwentyThirty
        elif 31 <= amount <= 50:
            return EpisodesAmount.ThirtyoneFifty
        elif 51 <= amount <= 100:
            return EpisodesAmount.FiftyoneOnehundred
        else:
            return EpisodesAmount.OnehundredonePlus
示例#16
0
from jikanpy import Jikan
import logging
import re
import requests
import shutil
import time

logging.basicConfig(filename='logs/scrape.log', level=logging.DEBUG)

anime_id = 21

jikan = Jikan()

characters_staff = jikan.anime(anime_id, extension='characters_staff')

chars = characters_staff['characters']

person_ids = set()
for c in chars:
    va = c['voice_actors']
    for v in va:
        if v['language'] == 'Japanese':
            person_ids.add(v['mal_id'])

for pid in person_ids:
    time.sleep(3)
    person = jikan.person(pid)
    name = re.sub('\s', '', person['name'])
    path = "tmp/raw_images/%s" % name
    url = person['image_url']
    r = requests.get(url, stream=True)
示例#17
0
def fetchAllAnimes():
    #jikan.season_later()
    #jikan.schedule()
    #top_anime = jikan.top(type='anime')
    #winter_2018 = jikan.season(year=2018, season='winter')
    animes = []
    jikan = Jikan()
    archive = jikan.season_archive()
    year = int(archive['archive'][0]['year'])
    d = enchant.Dict("en_US")
    while year >= 1975:
        for seasonname in archive['archive'][0]['seasons']:
            while True:
                try:
                    season = jikan.season(year=year, season=seasonname)
                    break
                except Exception as error:
                    if '429' in str(error):
                        print('[DetectAnime] Rate limited. Sleeping for 30secs...')
                        time.sleep(30)
                    else:
                        print(error)
                    pass

            for animesmall in season['anime']:
                id = animesmall['mal_id']
                while True:
                    try:
                        anime = jikan.anime(int(id))
                        break
                    except Exception as error:
                        if '429' in str(error):
                            print('[DetectAnime] Rate limited. Sleeping for 30secs...')
                            time.sleep(30)
                    else:
                        logging.error(error)
                    pass
                
                title = anime['title']
                engtitle = anime['title_english']
                japtitle = anime['title_japanese']
                synonym = anime['title_synonyms']
                try:
                    isValidTitle = len(title) > 4 and not d.check(title) and not d.check(re.sub('[^A-Za-z ]+', '', title))
                except Exception as e:
                    print('[DetectAnime] Error determining validity of title: ' + str(e) + '. Defaulting to False.')
                    isValidTitle = False
                if isValidTitle:
                    print(f'[DetectAnime] Appending "{title}" with id {id}. List size is now {len(animes)}.')
                    animes.append(title)
                    spacedreg = re.sub(r'[^\w]|[ ]', ' ', title)
                    if len(spacedreg) > 4:
                        animes.append(spacedreg)
                    blankedreg = re.sub(r'[^\w]|[ ]', '', title)
                    if len(blankedreg) > 4:
                        animes.append(spacedreg)
                try:
                    isValidTitle = len(engtitle) > 4 and not d.check(engtitle) and not d.check(re.sub('[^A-Za-z ]+', '', engtitle))
                except Exception as e:
                    print('[DetectAnime] Error determining validity of title: ' + str(e) + '. Defaulting to False.')
                    isValidTitle = False
                if isValidTitle:
                    print(f'[DetectAnime] Appending "{engtitle}" with id {id}. List size is now {len(animes)}.')
                    animes.append(engtitle)
                    spacedreg = re.sub(r'[^\w]|[ ]', ' ', engtitle)
                    if len(spacedreg) > 4:
                        animes.append(spacedreg)
                    blankedreg = re.sub(r'[^\w]|[ ]', '', engtitle)
                    if len(blankedreg) > 4:
                        animes.append(spacedreg)
                if not japtitle == None and len(japtitle) > 5:
                    print(f'[DetectAnime] Appending "{japtitle}" with id {id}. List size is now {len(animes)}.')
                    animes.append(japtitle)
                for syn in synonym:
                    if len(syn) > 4:
                        print(f'[DetectAnime] Appending synonym "{syn}" for "{title}". List size is now {len(animes)}.')
                        animes.append(syn)
                        spacedreg = re.sub(r'[^\w]|[ ]', ' ', syn)
                        if len(spacedreg) > 4:
                            animes.append(spacedreg)
                        blankedreg = re.sub(r'[^\w]|[ ]', '', syn)
                        if len(blankedreg) > 4:
                            animes.append(spacedreg)
                
        year -= 1
    animes = list(dict.fromkeys(animes))
    animes = removeDupStrings(animes)
    return animes
示例#18
0
class Container:

    def __init__(self, id: str, shared_info):
        self.shared_info = shared_info
        self.shared_info.pending_updates_main = True
        self.names_list = []
        self.graphs_list = []
        self.jikan = Jikan()
        self.div = html.Div(id="graphcontainer")

        self.status_children = "Status: No issues. Feel free to add graphs"
        self.max_graphs = False

        self.app = DjangoDash(id, external_stylesheets=external_stylesheets)
        self.genre_options = [
            {'label': 'Any', 'value': '1'},
            {'label': 'Action', 'value': '2'},
            {'label': 'Adventure', 'value': '3'},
            {'label': 'Cars', 'value': '4'},
            {'label': 'Comedy', 'value': '5'},
            {'label': 'Dementia', 'value': '6'},
            {'label': 'Demons', 'value': '7'},
            {'label': 'Mystery', 'value': '8'},
            {'label': 'Drama', 'value': '9'},
            {'label': 'Ecchi', 'value': '10'},
            {'label': 'Fantasy', 'value': '11'},
            {'label': 'Game', 'value': '12'},
            {'label': 'Hentai', 'value': '13'},
            {'label': 'Historical', 'value': '14'},
            {'label': 'Horror', 'value': '15'},
            {'label': 'Kids', 'value': '16'},
            {'label': 'Magic', 'value': '17'},
            {'label': 'Martial Arts', 'value': '18'},
            {'label': 'Mecha', 'value': '19'},
            {'label': 'Music', 'value': '20'},
            {'label': 'Parody', 'value': '21'},
            {'label': 'Samurai', 'value': '22'},
            {'label': 'Romance', 'value': '23'},
            {'label': 'School', 'value': '24'},
            {'label': 'Sci Fi', 'value': '25'},
            {'label': 'Shoujo', 'value': '26'},
            {'label': 'Shoujo Ai', 'value': '27'},
            {'label': 'Shounen', 'value': '28'},
            {'label': 'Shounen Ai', 'value': '29'},
            {'label': 'Space', 'value': '30'},
            {'label': 'Sports', 'value': '31'},
            {'label': 'Super Power', 'value': '32'},
            {'label': 'Vampire', 'value': '33'},
            {'label': 'Yaoi', 'value': '34'},
            {'label': 'Yuri', 'value': '35'},
            {'label': 'Harem', 'value': '36'},
            {'label': 'Slice Of Life', 'value': '37'},
            {'label': 'Supernatural', 'value': '38'},
            {'label': 'Military', 'value': '39'},
            {'label': 'Police', 'value': '40'},
            {'label': 'Psychological', 'value': '41'},
            {'label': 'Thriller', 'value': '42'},
            {'label': 'Seinen', 'value': '43'},
            {'label': 'Josei', 'value': '44'},

        ]

        self.category_options = [
            {'label': 'Any', 'value': '1'},
            {'label': 'TV', 'value': '2'},
            {'label': 'OVA', 'value': '3'},
            {'label': 'Movie', 'value': '4'},
            {'label': 'Special', 'value': '5'},
            {'label': 'ONA', 'value': '6'},
            {'label': 'Music', 'value': '7'},
        ]

        self.app.layout = self.serve_layout

        # @self.app.callback(
        #     Output('graphcontainer', 'children'),
        #     [Input('search_button', 'n_clicks'),
        #      State('searchname', 'value')]
        # )
        @self.app.callback(
            [Output('table', 'data'),
             Output('table', 'dropdown')],
            [Input('search_button', 'n_clicks'),
             Input("searchname", 'n_submit'),
             State("searchname", "value"),
             State('genre_dropdown', 'value'),
             State('category_dropdown', 'value'),
             State('date_picker_range', 'start_date'),
             State('date_picker_range', 'end_date')]
        )
        def update_table(n_clicks, n_submit, searchname, genre_dropdown, category_dropdown, start_date, end_date):
            data = [{'Name': "", 'Add Graph(s)': ""},
                    {'Name': "", 'Add Graph(s)': ""},
                    {'Name': "", 'Add Graph(s)': ""},
                    {'Name': "", 'Add Graph(s)': ""},
                    {'Name': "", 'Add Graph(s)': ""}]
            dropdown = {}

            if searchname is not None:
                data = []
                selected_genre = int(genre_dropdown) - 1
                selected_category = (self.category_options[int(category_dropdown) - 1]['label'])
                results = self.search_anime(searchname, selected_genre, selected_category, start_date, end_date)

                for x in range(0, len(results) - 1):
                    data.append({'Name': results[x]["title"], 'Add Graph(s)': "Don't add Graph"})

                dropdown = {
                    'Add Graph(s)': {
                        'options': [
                            {'label': "No", 'value': "Don't add Graph"},
                            {'label': "Yes", 'value': "Add Graph"}
                        ],
                        'searchable': False,
                        'clearable': False
                    }
                }

            return data, dropdown

        @self.app.callback(
            [Output('graphcontainer', 'children'),
             Output('status_message', 'children'),
             Output('add_graphs', 'disabled')],
            [Input('add_graphs', 'n_clicks'),
             State('table', 'data')]
        )
        def add_graph(n_clicks, data):
            id = 'graph-{}'.format(n_clicks)

            disable_add_button = self.max_graphs
            children = self.status_children

            names_added = []
            names_no_data = []
            names_duplicate = []
            names_above_max = []

            num_graphs = Anime.objects.count()

            if n_clicks > 0:
                for i in data:
                    if i['Add Graph(s)'] == 'Add Graph':
                        if num_graphs < 5:
                            if i['Name'] not in self.names_list:
                                try:
                                    test = graphs.Graphs(i['Name'] + 'app', i['Name'], i['Name'], i['Name'] + 'slider',
                                                         False,
                                                         [Input(i['Name'] + 'slider', 'value')],
                                                         self.shared_info.color_graphs,
                                                         self.shared_info.time_scale, i['Name'])
                                    self.graphs_list.append(test.return_layout())  # Potentially causes exception

                                    self.names_list.append(i['Name'])
                                    names_added.append(i['Name'])

                                    num_graphs = num_graphs + 1
                                    a = Anime(anime_name=i['Name'], anime_order=num_graphs)
                                    a.save()

                                except exceptions.ResponseError:
                                    names_no_data.append(i['Name'])

                            else:
                                names_duplicate.append(i['Name'])
                        else:
                            names_above_max.append(i['Name'])

                str_names = ""
                str_no_data = ""
                str_duplicates = ""
                str_above = ""

                if num_graphs == 5:
                    disable_add_button = True
                    self.max_graphs = True

                if len(names_added) > 0:
                    self.shared_info.pending_updates_edit = True
                    self.shared_info.pending_updates_export = True
                    str_names = "Added (" + str(num_graphs) + "/5 total limit): "
                    for i in names_added:
                        str_names = str_names + i + "; "
                if len(names_no_data) > 0:
                    str_no_data = "Not added (no search data or rate limit exceeded): "
                    for i in names_no_data:
                        str_no_data = str_no_data + i + "; "

                if len(names_duplicate) > 0:
                    str_duplicates = "Not added (duplicate graph): "
                    for i in names_duplicate:
                        str_duplicates = str_duplicates + i + "; "

                if len(names_above_max) > 0:

                    str_above = "Not added (exceeded 5-graph limit): "
                    for i in names_above_max:
                        str_above = str_above + i + "; "

                if len(str_names) > 0 or len(str_no_data) > 0 or len(str_duplicates) > 0 or len(str_above) > 0:
                    children = "Status - "
                    if len(str_names) > 0:
                        children = children + str_names
                    if len(str_no_data) > 0:
                        children = children + str_no_data
                    if len(str_duplicates) > 0:
                        children = children + str_duplicates
                    if len(str_above) > 0:
                        children = children + str_above

            return html.Div(self.graphs_list), children, disable_add_button

    def serve_layout(self):
        if self.shared_info.pending_updates_main:
            self.shared_info.pending_updates_main = False
            self.div = html.Div(children=self.init_graph(), id="graphcontainer")

        num_graphs = Anime.objects.count()

        if num_graphs == 5:
            self.status_children = "Status: Max graphs (5) limit reached. Graphs may be removed via 'Settings' page."
            self.max_graphs = True
        else:
            self.status_children = "Status: No changes made yet. Feel free to add graphs (" + str(
                num_graphs) + "/5 total limit)"
            self.max_graphs = False

        graph_area = self.div

        return html.Div([
            html.Div(
                id='searchtablearea',
                children=[
                    html.Div(
                        id='searcharea',
                        children=[
                            dcc.Input(
                                id='searchname',
                                type='text',
                                placeholder='Enter Show Name',
                                debounce=True,
                                n_submit=0
                            ),
                            html.Button(id="search_button", n_clicks=0, children="Search"),
                            html.P('Genre:'),
                            dcc.Dropdown(id='genre_dropdown',
                                         options=self.genre_options,
                                         value='1',
                                         clearable=False
                                         ),

                            html.P('Category:'),
                            dcc.Dropdown(id='category_dropdown',
                                         options=self.category_options,
                                         value='1',
                                         clearable=False
                                         ),

                            html.P('Select search range:'),

                            dcc.DatePickerRange(
                                id='date_picker_range',
                                start_date_placeholder_text='Select start date',
                                end_date_placeholder_text='Select end date',
                                clearable=True,
                            ),
                        ]),
                    html.Div(
                        id='tablearea',
                        children=
                        [self.init_table(),
                         html.P(id='status_message', children=self.status_children, style={'font-style': 'italic'}),
                         html.Button(id="add_graphs", n_clicks=0, children="Add selected graphs",
                                     disabled=self.max_graphs),
                         ])
                ]),
            graph_area,
        ])

    def init_graph(self):
        initial_graphs = []
        self.graphs_list = []
        self.names_list = []
        for a in Anime.objects.raw('SELECT anime_name FROM home_anime ORDER BY anime_order ASC'):
            p = str(a)
            self.names_list.append(p)
            initial_graphs.append(
                graphs.Graphs(p.replace(" ", ""), p, p.replace(" ", ""), p.replace(" ", "") + 'slider', False,
                              [Input(p.replace(" ", "") + 'slider', 'value')], self.shared_info.color_graphs,
                              self.shared_info.time_scale, p))

        if len(initial_graphs) != 0:
            for i in initial_graphs:
                self.graphs_list.append(i.return_layout())

        return html.Div(self.graphs_list)

    def search_anime_gender_birthday(self, anime_id):
        data = [sub['username'] for sub in self.jikan.anime(anime_id, extension='userupdates', page=1)["users"]]
        user = [self.jikan.user(username=name) for name in data]
        print(name['birthday'] for name in user)
        print(name['gender'] for name in user)

    def search_anime(self, anime_name, genre_number, category_name, start_date, end_date):
        search_params = {}

        if genre_number > 0:
            search_params['genre'] = genre_number

        if category_name != "Any":
            search_params['type'] = category_name

        if start_date is not None:
            search_params['start_date'] = start_date

        if end_date is not None:
            search_params['end_date'] = end_date

        search = self.jikan.search('anime', anime_name, parameters=search_params)

        # user = self.jikan.user_list(38000)
        # print(user)
        # print(user['birthday'])
        # print(user['gender'])
        return search["results"]

    def init_table(self, type: str = 'Add', pg_size: int = 5):
        layout = dash_table.DataTable(
            id='table',
            style_cell={'textAlign': 'left'},
            style_data_conditional=[
                {
                    "if": {"state": "active"},  # 'active' | 'selected'
                    "backgroundColor": "#FFFFFF",
                    "border": "1px solid #3CCFCF",
                },
                {
                    "if": {"state": "selected"},
                    "backgroundColor": "##FFFFFF",
                    "border": "1px solid #3CCFCF",
                },
            ],
            style_header={
                'backgroundColor': 'rgb(230, 230, 230)',
                'fontWeight': 'bold'
            },
            columns=[{"name": "Name",
                      "id": "Name",
                      "editable": False
                      },
                     {"name": type + ' Graph(s)',
                      "id": type + ' Graph(s)',
                      "presentation": "dropdown",
                      "editable": True,
                      }
                     ],
            dropdown={},
            data=[{'Name': "", 'Add Graph(s)': ""},
                  {'Name': "", 'Add Graph(s)': ""},
                  {'Name': "", 'Add Graph(s)': ""},
                  {'Name': "", 'Add Graph(s)': ""},
                  {'Name': "", 'Add Graph(s)': ""}],
            page_size=pg_size,
        )

        return layout
示例#19
0
from anime.models import Anime
from jikanpy import Jikan, exceptions

jikan = Jikan()

idx = 1
for _ in range(1, 41000):
    try:
        json = jikan.anime(idx)
        Anime.objects.create(title=json['title'],
                             title_jap=json['title_japanese'],
                             img_url=json['image_url'],
                             type=json['type'],
                             season=json['premiered'],
                             status=json['status'],
                             air_date=json['aired']['string'],
                             synopsis=json['synopsis'])
    except exceptions.APIException as e:
        pass
    idx += 1
示例#20
0
class MALHandler(object):
    def __init__(self):
        self.jikan = Jikan()
        self.fileHandler = FileHandler()
        self.dataPath = './data/meta'
        self.labelPath = './label/meta'
        self.allSeoson = ['spring', 'summer', 'fall', 'winter']

    def getDetailSynopsisAndScore(self, id):
        detail_anime = self.jikan.anime(id)
        return detail_anime['score']

    def getAnimeData(self, year, season):
        print('Getting all anime in {} {}'.format(year, season))
        animeData = self.jikan.season(year=year, season=season)
        input = []
        label = []
        for anime in animeData['anime']:
            print('total:{}, processed:{}'.format(len(animeData['anime']),
                                                  len(input)))
            synopsis = anime['synopsis']
            synopsis = ' '.join(synopsis.splitlines())
            synopsis = synopsis.replace('  ', ' ')
            if anime['score'] is None:
                while True:
                    try:
                        score = self.getDetailSynopsisAndScore(anime['mal_id'])
                    except:
                        time.sleep(10)
                    else:
                        break
            else:
                score = anime['score']

            label.append(str(score))
            input.append(synopsis)
        return input, label

    def saveAnimeData(self, year, season):
        input, label = self.getAnimeData(year, season)
        self.fileHandler.saveFileHandler(
            '{}/{}_{}_data.txt'.format(self.dataPath, year, season), input)
        self.fileHandler.saveFileHandler(
            '{}/{}_{}_label.txt'.format(self.labelPath, year, season), label)

    def loadData(self, year, season):

        data = self.fileHandler.loadFileHandler('{}/{}_{}_data.txt'.format(
            self.dataPath, year, season))
        label = self.fileHandler.loadFileHandler('{}/{}_{}_label.txt'.format(
            self.labelPath, year, season))
        if len(data) != len(label):
            raise RuntimeError('Input and label numbers not match!')
        return data, label

    def savaAllSeasonAnimeData(self, year):
        for season in self.allSeason:
            self.saveAnimeData(year, season)

    def run(self, formYear, toYear):
        for year in range(formYear, toYear):
            for season in self.allSeoson:
                self.saveAnimeData(year, season)

with open('submissions/AnimeSoc Termly Anime Nomination Form (Responses) - Form responses 1.csv',newline='') as csvfile:
    readCSV = csv.reader(csvfile,delimiter=',')

    for row in readCSV:
        currentitem = 4
        while currentitem <= 16:
            id = ''
            for i in row[currentitem+1]:
                if str.isdigit(i):
                    id=id+i
                if i == '/' and len(id) > 1:
                    break
            if row[currentitem+2] == 'Slot A':
                slotA.append([row[currentitem],row[currentitem+1],str(row[currentitem+3]).replace("'","\'"),jikan.anime(id).get("image_url"),jikan.anime(id).get("synopsis").replace("'","\'")])
            elif row[currentitem+2] == 'Slot B':
                slotB.append([row[currentitem],row[currentitem+1],str(row[currentitem+3]).replace("'","\'"),jikan.anime(id).get("image_url"),jikan.anime(id).get("synopsis").replace("'","\'")])
            elif row[currentitem+2] == 'Slot C':
                slotC.append([row[currentitem],row[currentitem+1],str(row[currentitem+3]).replace("'","\'"),jikan.anime(id).get("image_url"),jikan.anime(id).get("synopsis").replace("'","\'")])
            time.sleep(4)
            currentitem+=4

with open('Slot A.csv', 'w') as csvfile:
    filewriter = csv.writer(csvfile,delimiter=',')
    filewriter.writerow(['Title','MAL Link','Nomination Description','Image URL','Synopsis'])
    for row in slotA:
        filewriter.writerow([row[0],row[1],row[2],row[3],row[4]])

with open('Slot B.csv', 'w') as csvfile:
    filewriter = csv.writer(csvfile,delimiter=',')
示例#22
0
from jikanpy import Jikan

jikan = Jikan()

mushishi = jikan.anime(39617)
mushishi_with_eps = jikan.anime(21, extension='episodes', page=10)

search_result = jikan.search('anime', 'One Piece', page=1)

winter_2018_anime = jikan.season(year=2021, season='winter')

archive = jikan.season_archive()

for anime in winter_2018_anime['anime']:
    if anime['title'] == 'One Piece':
        print(anime)

print(archive)
print(winter_2018_anime)
print(search_result)
示例#23
0
from jikanpy import Jikan
jikan = Jikan()

# json of all anime info specified by Jikan docs
mushishi = jikan.anime(id=457, page=2)
# mushishi = jikan._get(endpoint="anime",id=457, page=2, extension=None)

print(mushishi)

# # same as above, but with extra info
# # see Jikan docs for information about which endpoints have which extensions
# mushishi_with_eps = jikan.anime(457, extension='episodes')
# mushishi_with_eps_2 = jikan.anime(457, extension='episodes', page=2)
# mushishi_with_characters_and_staff = jikan.anime(457, extension='characters_staff')

# # you can also query characters
# ginko = jikan.character(425)

# # and manga
# mushishi_manga = jikan.manga(418)

# # search up people too
# kana_hanazawa = jikan.person(185)

# # search
# search_result = jikan.search('anime', 'Mushishi')
# # add a page number to the search request
# search_result = jikan.search('anime', 'Mushishi', page=2)
# # add a filter to the search (see Jikan docs about what filters are legal)
# search_result = jikan.search('anime', 'Mushishi', parameters={'type': 'tv'})
# search_result = jikan.search('anime', 'Mushishi', parameters={'genre': 37})
示例#24
0
animeFallback = 'https://animepahe.com'

MALRegex = re.compile(r'''
myanimelist.net/anime/
''', re.VERBOSE)

anilistRegex = re.compile(r'''
anilist.co/anime/
''', re.VERBOSE)

try:
    address = pyperclip.paste()

    if bool(MALRegex.search(address)):  # check if the link is MAL
        MALid = address.split('/')[4]
        search_result = jikan.anime(MALid)
        title = search_result['title']
        webbrowser.open(animepaheLink.getAnimePahe(title))

    elif bool(anilistRegex.search(address)):  # check if the link is Anilist
        ALid = address.split('/')[4]
        title = anilistLink.anilistTitle(ALid)
        webbrowser.open(animepaheLink.getAnimePahe(title))

    else:
        webbrowser.open(
            animeFallback
        )  # will launch animepahe's homepage if the selected link is invalid

except IndexError as error:
    print('Link is invalid. Please try again.')
示例#25
0
from hikka.services.anime import AnimeService
from hikka.services.files import FileService
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"]
示例#26
0
class MAL_Series(object, metaclass=MAL_SeriesMemoizer):
    def __init__(self, id=None, *, name=None):
        self._jikan = Jikan()
        self.id = id
        self._raw = self._jikan.anime(self.id)
        self._cached = self._raw['request_cached']
        # MAL meta info
        self.url = self._raw['url']
        self.image_url = self._raw['image_url']
        # titles
        self.title = self._raw['title']
        self.title_en = self._raw['title_english']
        self.title_jp = self._raw['title_japanese']
        self.synonyms = self._raw['title_synonyms']
        # series meta info
        self.type = AnimeType(self._raw['type'])
        self.source = AnimeSource(self._raw['source'])
        self.status = AiringStatus(self._raw['status'])
        self.score = self._raw['score']
        self.rank = self._raw['rank']
        # release date info
        self.airing = self._raw['airing']  # bool
        if not self._raw['aired']['from']:
            self.premiered = None
        else:
            self.premiered = isoparse(self._raw['aired']['from'])
        if not self._raw['aired']['to']:
            self.ended = None
        else:
            self.ended = isoparse(self._raw['aired']['to'])
        self.release_run = self._raw['aired']['string']
        self.release_season = self._raw['premiered']
        # series info
        self.synopsis = self._raw['synopsis']
        self.background = self._raw['background']
        self.studio = self._raw['studios']
        self.rating = self._raw['rating']
        self.episodes = self.fetch_episodes()
        try:
            self._sequel_id = self._raw['related'].get('Sequel')[0]['mal_id']
        except TypeError:
            self._sequel_id = None
        try:
            self._prequel_id = self._raw['related'].get('Prequel')[0]['mal_id']
        except TypeError:
            self._prequel_id = None

    @property
    def sequel(self):
        return MAL_Series(self._sequel_id) if self._sequel_id else None

    @property
    def prequel(self):
        return MAL_Series(self._prequel_id) if self._prequel_id else None

    def fetch_episodes(self):
        """
        Fetch all episodes of a series (automatically de-paginates, so we
        *actually* get them all, not just the first page)
        """
        resp = self._jikan.anime(self.id, extension='episodes')
        episodes = resp['episodes']
        last_page = resp['episodes_last_page']
        if last_page > 1:
            for i in range(2, last_page + 1):
                episodes += self._jikan.anime(self.id,
                                              extension='episodes',
                                              page=i)['episodes']
        # return as episode object
        return [MAL_Episode(self, ep) for ep in episodes]

    def __repr__(self):
        return f"<MAL_Series: {self.title} [{self.id}]>"
示例#27
0
    # get page data
    page_num = 1
    print('[I] Doing page number ' + str(page_num))
    page = jikan.user(username, 'animelist', list_type, page_num)
    anime_list = page['anime']

    while len(anime_list) > 0:
        anime_in_page_done = 0
        for idx_anime, anime in enumerate(anime_list):
            if page_lim_enable and anime_in_page_done >= page_lim:
                print('[I] Debug limit (' + str(page_lim) + ') reached')
                break  # break if page limit exceeded

            mal_id = anime['mal_id']
            anime_page = jikan.anime(mal_id)
            title = anime_page['title']

            to_search = [
                title + ' op ' + str(i + 1)
                for i in range(len(anime_page['opening_themes']))
            ]
            to_search.extend([
                title + ' ed ' + str(i + 1)
                for i in range(len(anime_page['ending_themes']))
            ])

            print('[I] Got page for "' + title + '" (' + str(mal_id) + ')')

            already_downloaded = []
            for idx_video, request in enumerate(to_search):
base_dir = "../data/reviews_small"
source = "../data/anime_data.csv"
codes_df = pd.read_csv(source)
num_reviews = 5
time_between_requests = 3  # in seconds

if not os.path.isdir(base_dir):  # If the base_dir does not exist create it
    os.mkdir(base_dir)

jikan = Jikan()

#scrap the reviews starting from the lower_bound
for index, row in codes_df.iterrows():
    # Put an upper bound on the amoun of reviews to reduce the inbalance problem
    try:
        reviews = jikan.anime(row["code"],
                              extension='reviews')['reviews'][:num_reviews]
        time.sleep(
            time_between_requests
        )  # wait before making too many requests as per API guidelines

    except APIException as e:
        #If myanimelist refuses the connection stop the scrapping and resume some time later
        logging.error(f"The server did not respond when scrapping {index}: " +
                      str(e))

        try:
            print("Retrying after 15 seconds...")
            time.sleep(15)
            reviews = jikan.anime(row["code"],
                                  extension='reviews')['reviews'][:num_reviews]
示例#29
0
logging.basicConfig(level=logging.ERROR)

base_dir = "../data/recommendations"
source = "../data/anime_data.csv"
codes_df = pd.read_csv(source)
time_between_requests = 4  # in seconds

if not os.path.isdir(base_dir):  # If the base_dir does not exist create it
    os.mkdir(base_dir)

jikan = Jikan()

#scrap the recommendations starting from the lower_bound
for index, row in codes_df.iterrows():
    try:
        recommendations = jikan.anime(row["code"], extension='recommendations')['recommendations']
        time.sleep(time_between_requests)  # wait before making too many requests as per API guidelines

    except APIException as e:
        #If myanimelist refuses the connection stop the scrapping and resume some time later
        logging.error(f"The server did not respond when scrapping {index}: " + str(e))
        
        try:
            print("Retrying after 15 seconds...")
            time.sleep(15)
            recommendations = jikan.anime(row["code"], extension='recommendations')['recommendations']

        except APIException as e:
            #If myanimelist refuses the connection stop the scrapping and resume some time later
            logging.error(f"The server did not respond again when scrapping {index}: " + str(e))
            continue
示例#30
0
from jikanpy import Jikan
from pprint import pprint

jikan = Jikan()

mushishi = jikan.anime(457)
pprint(mushishi)

fma = jikan.manga(25)
pprint(fma)

ginko = jikan.character(425)
pprint(ginko)

kana_hanazawa = jikan.person(189)
pprint(kana_hanazawa)

naruto = jikan.search(search_type='anime', query='naruto')
pprint(naruto)

winter_2018 = jikan.season(year=2018, season='winter')
pprint(winter_2018)

archive = jikan.season_archive()
pprint(archive)

later = jikan.season_later()
pprint(later)

monday = jikan.schedule(day='monday')
pprint(monday)