This is the first phase in my project to analyse my anime watch history. Here, I outline my approach to collecting metadata for each anime title I’ve watched and all its related franchise entries from MyAnimeList’s public database using the Jikan API. This code takes my personal watched anime list as input and outputs a CSV file containing detailed metadata for every related anime entry, grouped by franchise.

*MyAnimeList (MAL) is one of the world’s largest anime and manga cataloguing platforms, with over 26,000 anime entries and 68,000 manga as of 2024.*

*Jikan (時間) is an unofficial, open-source API that provides structured access to MAL’s data, since MyAnimeList itself does not have a full public API.*

You can find the full code on my GitHub here.

Toolkit:


API Setup: URL and Request Handling

First, I define a global constant for the API endpoint:

URL = "https://api.jikan.moe/v4"

The get_data function is a helper used for almost all API requests in this project. By calling it wherever needed (instead of copy-pasting network logic), it ensures consistent, readable, and robust data fetching.

How it works:

Centralising all API calls in a single function keeps the script clean, avoids duplication, and ensures consistent error handling and retry logic. This pattern increases both reliability and maintainability in the data collection workflow.

def get_data(url, params=None, max_retries=5, wait=1):
    """Performs a GET request with basic retry logic and 
    error handling for robust data collection.
    """

    retries = 0

    while retries < max_retries:
        time.sleep(wait)
        try:
            resp = requests.get(url, params=params)
            if resp.status_code == 429:
                print(f"⚠️ Rate limited at {url}, retrying ({retries+1}/{max_retries})…")
                time.sleep(10)
                retries += 1
                continue
            resp.raise_for_status()
            return resp
        
        except requests.exceptions.HTTPError as e:
            print(f"❌ Request failed for {url} due to {e}")
            return None
        except Exception as e:
            print(f"❌ Unexpected error on attempt {retries+1} for {url}: {e}")
            return None
        
    print(f"❌ Max retries exceeded for {url}")
    return None

Text Normalisation and Fuzzy Matching

The next step is to clean and normalise the anime title strings so they can be matched with entries in the MAL database as efficiently as possible. This process handles differences in punctuation, spacing, spelling, and capitalisation. Here, each title is normalised (cleaned up), split into word tokens, and compared using fuzzy matching - so that even titles that aren’t identical (due to minor differences) can still be recognised as matches.

Functions Used: