aboutsummaryrefslogtreecommitdiff
path: root/internal/mal_wrapper.py
blob: aaa44138c513c9cf2202a81dc5ef3510c9a187c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests


def get_mal_recent_activity(username):
    url = f"https://api.jikan.moe/v4/users/{username}/userupdates"
    response = requests.get(url)
    if response.status_code == 200:
        anime = []
        manga = []

        for entry in response.json()["data"]["anime"]:
            anime.append(
                {
                    "id": entry["entry"]["mal_id"],
                    "url": entry["entry"]["url"],
                    "image_url": entry["entry"]["images"]["jpg"]["image_url"],
                    "title": entry["entry"]["title"],
                    "score": entry["score"],
                    "status": entry["status"],
                    "episodes_seen": entry["episodes_seen"],
                    "episodes_total": entry["episodes_total"],
                    "date": entry["date"],
                }
            )

        for entry in response.json()["data"]["manga"]:
            manga.append(
                {
                    "id": entry["entry"]["mal_id"],
                    "url": entry["entry"]["url"],
                    "image_url": entry["entry"]["images"]["jpg"]["image_url"],
                    "title": entry["entry"]["title"],
                    "score": entry["score"],
                    "status": entry["status"],
                    "chapters_read": entry["chapters_read"],
                    "chapters_total": entry["chapters_total"],
                    "volumes_read": entry["volumes_read"],
                    "volumes_total": entry["volumes_total"],
                    "date": entry["date"],
                }
            )

        return {"anime": anime, "manga": manga}
    else:
        return None