| 
30
 | 
     1 import urllib.request, json, re, sys
 | 
| 
 | 
     2 
 | 
| 
 | 
     3 id = input("What is the MyAnimeList ID for your anime?: ")
 | 
| 
 | 
     4 try:
 | 
| 
 | 
     5     temp = int(id)
 | 
| 
 | 
     6 except:
 | 
| 
 | 
     7     print("Not a valid MyAnimeList ID! Exiting.")
 | 
| 
 | 
     8     sys.exit()
 | 
| 
 | 
     9 
 | 
| 
 | 
    10 with urllib.request.urlopen(f"https://api.jikan.moe/v3/anime/{str(id)}/episodes") as url:
 | 
| 
 | 
    11     data = json.loads(url.read().decode())
 | 
| 
 | 
    12     count = 0
 | 
| 
 | 
    13     for i in range(len(data["episodes"])):
 | 
| 
 | 
    14         if count == 0:
 | 
| 
 | 
    15             f = open("list.txt", "w", encoding="utf-8")
 | 
| 
 | 
    16         else:
 | 
| 
 | 
    17             f = open("list.txt", "a", encoding="utf-8")
 | 
| 
 | 
    18         """
 | 
| 
 | 
    19         this is really hard to read at first glance so i'll break it down
 | 
| 
 | 
    20         it replaces "?" and ":" with legal counterparts so windows stops screaming
 | 
| 
 | 
    21         then strips among a dash (which usually shows different parts in an episode)
 | 
| 
 | 
    22         it then removes the last part of the string cause most, if not of MAL's have spaces before slashes
 | 
| 
 | 
    23         """
 | 
| 
 | 
    24         f.write(data["episodes"][count]["title"].replace("?", "?").replace(":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n")
 | 
| 
 | 
    25         count += 1
 | 
| 
 | 
    26         f.close()
 |